I have this form in my MVVM application.
<UserControl xmlns:behaviors="clr-namespace:...."> ....<UserControl.InputBindings><KeyBinding Key="D1" Command="{Binding KeyCommand}" CommandParameter="{x:Static behaviors:HotKeyCommand.Random}"/></UserControl.InputBindings><Grid> ...<TextBox Name="N1" behaviors:TextBoxBehavior.Check="true"> ...</Grid></UserControl>
In "behaviors" setallowed keys input for TextBox:
private static void CheckPreviewKeyDown(object sender, KeyEventArgs e) { switch (e.Key) { case Key.NumPad0: case Key.NumPad1: case Key.NumPad2: break; default: e.Handled = true; break; } }The problem is when field "N1" is focused, the KeyBinding Key="D1" not working, because CheckPreviewKeyDown handled key D1. I can't removeCheckPreviewKeyDown, because this TextBox must allowed only numbers from numpad keys. How can I solve my problem?