Create a simple, unmodified key binding in WPF

前端 未结 1 492
抹茶落季
抹茶落季 2020-12-20 15:26

I\'m trying to create a very simple WPF application. I\'d like to have an command handler called when the user presses \"H\" (not Control-H or Alt-H, just H). If I use the

相关标签:
1条回答
  • 2020-12-20 16:23

    Don't use the KeyGesture type or property (as one key is not a gesture).

    e.g.

    KeyBinding b = new KeyBinding()
        {
            Command = MyRoutedCommand,
            Key = Key.H
        };
    InputBindings.Add(b);
    

    Same for XAML

    <KeyBinding Command="{Binding MyRoutedCommand}" Key="H" />
    
    0 讨论(0)
提交回复
热议问题