Create Key binding in WPF

后端 未结 5 1877
滥情空心
滥情空心 2020-11-30 08:47

I need to create input binding for Window.

public class MainWindow : Window
{
    public MainWindow()
    {
        SomeCommand = ??? () => OnAction();
           


        
5条回答
  •  执念已碎
    2020-11-30 09:10

    It might be too late but here is the simplest and shortest solution.

    private void Window_KeyDown(object sender, KeyEventArgs e)
    {
        if (Keyboard.Modifiers == ModifierKeys.Control && e.Key == Key.S)
        {
             // Call your method here
        }
    }
    
    
    

提交回复
热议问题