Search code examples
wpfbindingkeyboard-shortcutskey-bindings

Multiple Keys in KeyBinding?


I want to setup hotkeys in my Wpf application. Using KeyBindings works in the simple case, for example: Ctrl+B, Ctrl+A, etc

<KeyBinding Gesture="Ctrl+B" Command="{Binding Source={StaticResource localCusomCommands}, Path=AddTTRowCommand}" ></KeyBinding>

<KeyBinding Modifiers="Control" Key="B" Command="{Binding Source={StaticResource localCusomCommands}, Path=AddTTRowCommand}" ></KeyBinding>

But if I need hotkeys with multiple keys Ctrl+P+B, Ctrl+A+B, etc

<KeyBinding Modifiers="Control" Key="P,B" Command="{Binding Source={StaticResource localCusomCommands}, Path=AddTTRowCommand}" ></KeyBinding>

Don't work.

<KeyBinding Gesture="Ctrl+B+A" Command="{Binding Source={StaticResource localCusomCommands}, Path=AddTTRowCommand}" ></KeyBinding>

Don't compile. Error 15 Unrecognized ModifierKeys 'B'.

How to achieve this?


Solution

  • As i told, there is implementation for overriding the KeyBinding and Gestures for multiple keys. refer the below link. He has overriden the implemetation of InputGesture to achieve this multikeybinding. http://kent-boogaart.com/blog/multikeygesture