How to make WPF TextBox end-to-end ApplicationCommands?

TextBox WPF grabs Ctrl-Z and Ctrl-Y for its own delete / redo. This is usually great, but in our application we have text fields that I don’t want to have, but instead we move on to the general application, which is treated as global cancellation.

I realized that I can override text field processing by adding CommandBindings for ApplicationCommands.Undo / Redo.

My question is: how can I "forward" those bindings to an element of the parent structure in order to eventually go to the application handler that I installed in the main window?

Update: Thanks to AndrewS, it turned out that I needed to set IsUndoEnabled to false. Then the application commands are ignored, and the top-level window can process them. Hurrah!

+6
source share
1 answer

You need to register a KeyBinding for the shortcut and associate it with ApplicationCommands.NotACommand. eg.

<TextBox> <TextBox.InputBindings> <KeyBinding Key="Y" Modifiers="Control" Command="NotACommand" /> <KeyBinding Key="Z" Modifiers="Control" Command="NotACommand" /> </TextBox.InputBindings> </TextBox> 
+10
source

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


All Articles