I'm writing my first WPF application and am trying to get my custom commands to work.
public static RoutedUICommand Header1 { get; private set; }
.
.
.
gestures = new InputGestureCollection();
gestures.Add(new KeyGesture(Key.D1, ModifierKeys.Control, "Ctrl+1"));
Header1 = new RoutedUICommand("Header 1", "Header1", typeof(EditCommands), gestures);
I then added a CommandBindings
section to my window's XAML.
<!-- local refers to my application's namespace -->
<Window.CommandBindings>
<CommandBinding Command="local:EditCommands.Header1" Executed="CommandBinding_Executed" CanExecute="CommandBinding_CanExecute"></CommandBinding>
</Window.CommandBindings>
And, finally, added a command entry to the associated Ribbon control.
<RibbonButton Label="Header 1" Command="local:EditCommands.Header1" SmallImageSource="Images\small.png" ToolTipTitle="Header 1" ToolTipDescription="" ToolTipImageSource="Images\small.png"></RibbonButton>
Clicking the Ribbon button executes the handler as expected. However, pressing Ctrl+1
seems to have no effect at all. How can I have my hot key recognized?