0

I have a button that has the following commands:

<Window.Resources>
    <RoutedUICommand x:Key="CommandPretraga"/>
</Window.Resources>

<Window.CommandBindings>
    <CommandBinding Command="{StaticResource CommandPretraga}" Executed="chkPretraga_Click" />
</Window.CommandBindings>

<Window.InputBindings>
    <KeyBinding Key="ENTER" Command="{StaticResource CommandPretraga}" />
</Window.InputBindings>

The shortcut works if called from most of the window, but if I'm currently in one of my TextBox elements, the shortcut doesn't work. I'm guessing that this is because the TextBox is registering and processing the ENTER key event, and I tried catching that and calling the same function the shortcut is supposed to call, but that didn't work.

How can I solve this?

NLuburić
  • 912
  • 1
  • 10
  • 28
  • 1
    Is your TextBox multiline? If yes, then there is no clean solution/workaround. I would try removing the multiline property if that is not against the requirements. – Nishant Jun 10 '13 at 14:57
  • Have you seen this question and answer? http://stackoverflow.com/questions/1361350/keyboard-shortcuts-in-wpf – Darlene Jun 10 '13 at 21:14

1 Answers1

1

You can intercept the keystrokes in the PreviewKeyDown event.

If the input is a defined shortcut, raise the corresponding event and set e.Handled to true, to prevent further processing of it.

Drasive
  • 321
  • 1
  • 20