1
2
3
4
5
6
7
8
9
10
11
<Window>
<Window.Resources>
    <RoutedUICommand x:Key="CommandDefualtButton" Text="CommandDefualtButton_C"/>
</Window.Resources>
<Window.InputBindings>
    <KeyBinding Gesture="Ctrl+D" Command="{StaticResource ResourceKey=CommandDefualtButton}"/>
</Window.InputBindings>
<Window.CommandBindings>
    <CommandBinding Command="{StaticResource ResourceKey=CommandDefualtButton}" CanExecute="CommandBinding_CanExecute" Executed="CommandBinding_Executed"/>
</Window.CommandBindings>
</Window>

这段XAML的意思就是先建立一个”RoutedUICommand”,x:key为CommandDefualtButton,然后响应”Ctrl+D”的KeyBinding,用”CommandBinding_CanExecute”来判断是否满足CommandBinding的执行条件,如果满足就执行”CommandBinding_Executed”.