单个 RoutedUICommand 的多个 KeyGesture

Multiple KeyGestures for a single RoutedUICommand

单个RoutedUICommand是否可以有2个或更多KeyGestures

例如:用户希望能够按SpaceAlt+P 播放视频。

目前,如果我将两个 KeyGestures 都设置为一个 RoutedUICommand,它会期望两者都被按下以执行。

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")
       });

那么,我可以将多个 KeyGestures 设置为单个 RoutedUICommand 吗?如果是,怎么做?

是的,您可以为同一个命令添加多个键绑定,如下所示,

<UserControl.InputBindings>
    <KeyBinding Modifiers="Alt" Key="P" Command="{Binding PlayCommand}" />
    <KeyBinding Key="Space" Command="{Binding PlayCommand}" />        
</UserControl.InputBindings>