Last active
September 17, 2021 15:08
-
-
Save Mahno74/28488aafaa7e1cd7d2ee27f62aeb07e3 to your computer and use it in GitHub Desktop.
WPF Создание команд горячих клавишь
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Создаем класс | |
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