Skip to content

Instantly share code, notes, and snippets.

@Mahno74
Last active September 17, 2021 15:08
Show Gist options
  • Save Mahno74/28488aafaa7e1cd7d2ee27f62aeb07e3 to your computer and use it in GitHub Desktop.
Save Mahno74/28488aafaa7e1cd7d2ee27f62aeb07e3 to your computer and use it in GitHub Desktop.
WPF Создание команд горячих клавишь
//Создаем класс
using System.Windows.Input;
namespace WPFWeekReport {
public class Commands {
static Commands() {
Save = new RoutedCommand("Save", typeof(MainWindow));
}
public static RoutedCommand Save { get; set; }
}
}
//добавляем в xaml
<Window.CommandBindings>
<CommandBinding Command="local:Commands.Save" Executed="SaveManual"/>
</Window.CommandBindings>
<Window.InputBindings>
<KeyBinding Command="local:Commands.Save" Key="S" Modifiers="Control"/>
</Window.InputBindings>
//добавляем а меню
<MenuItem Header="Сохранить" Command="local:Commands.Save" InputGestureText="Crtrl-S"/>
//Функция в коде C#
private void SaveManual(object sender, RoutedEventArgs e)
{
MessageBox.Show(@"Сохранено успешно", @"Сохранение");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment