WPF KeyBinding smooths keys, preventing the use of TextBox

Problem Overview:
Anyone KeyBindingdefined at a higher level TextBox(without modifier keys assigned) does not allow the user to enter these keys internally TextBox.

Minimum XAML hierarchy:

<Window>
  <UserControl>
    <Border>
      <UserControl>
        <TextBox>

Minimum command / KeyBinding:

<UserControl.Resources>
    <RoutedUICommand x:Key="Commands.SomeCommand" />
</UserControl.Resources>
<UserControl.InputBindings>
    <KeyBinding Key="A" Command="{StaticResource Commands.SomeCommand} />
</UserControl.InputBindings>
<UserControl.CommandBindings>
    <CommandBinding Command="{StaticResource Commands.SomeCommand}" Executed="..." />
</UserControl.CommandBindings>

Command KeyBinding UserControl. , , A, . , TextBox.KeyDown TextBox.PreviewKeyDown , A ( Handled = false), TextBox.PreviewTextInput .

, , TextBox - , .

EDIT:
Snoop .

  • TextBox.PreviewKeyDown , Window TextBox
  • TextBox.KeyDown , TextBox
  • TextBox.KeyDown Handled true UserControl, KeyBinding.
  • TextBox.PreviewTextInput , , KeyDown .

, UserControl , ? , , .

+4
2

TextInput PreviewTextInput / .

, , Command (Preview) TextInput .

- - KeyBinding, , .

e.Handle PreviewKeyDown TextBox TextComposition , - :

target.RaiseEvent(new TextCompositionEventArgs(InputManager.Current.PrimaryKeyboardDevice, 
new TextComposition(InputManager.Current, target, "A")) 
{ 
    RoutedEvent = TextCompositionManager.TextInputEvent 
});

( , textBox.Text CaretIndex)

, .

0

Source: https://habr.com/ru/post/1611667/


All Articles