Reputation: 3358
Is it possible to have 2 or more KeyGestures
for a single RoutedUICommand
?
For example: User wants to be able to press Space or Alt+P to play a video.
Currently, if I set both KeyGestures
to a RoutedUICommand
, it will expect both to be pressed to execute.
private static RoutedUICommand _play = new RoutedUICommand("Play", "Play", typeof(Commands),
new InputGestureCollection
{
new KeyGesture(Key.P, ModifierKeys.Alt, "Alt + P"),
new KeyGesture(Key.Space, ModifierKeys.None, "Space")
});
So, can I set multiple KeyGestures
to a single RoutedUICommand
? If so, how?
Upvotes: 0
Views: 165
Reputation: 2956
Yes you can add multiple keyBindings for same Command like below,
<UserControl.InputBindings>
<KeyBinding Modifiers="Alt" Key="P" Command="{Binding PlayCommand}" />
<KeyBinding Key="Space" Command="{Binding PlayCommand}" />
</UserControl.InputBindings>
Upvotes: 1