2016-05-03 55 views
0

單個RoutedUICommand是否可以有兩個或更多個KeyGestures單個RoutedUICommand的多個KeyGestures

例如:用戶希望能夠按空間Alt + 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?如果是這樣,怎麼樣?

回答

1

是的,你可以爲同一個命令添加多個鍵綁定像下面,

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

大。我可以將'KeyBindings'直接註冊到'RoutedUICommand'嗎? –

+0

是的,我相信。我還沒有嘗試過。 –