Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a WPF TextBox pass-through ApplicationCommands?

Tags:

wpf

The WPF TextBox captures Ctrl-Z and Ctrl-Y for its own undo/redo. Normally great, but in our app we have some text boxes that I don't want to have this behavior, but to instead pass through to the overall app to handle as global undo.

I figured out I can override the text boxes' handling of these by adding CommandBindings for ApplicationCommands.Undo/Redo.

My question: how can I 'forward' those bindings to the parent framework element so that it eventually routes to the app's handler I installed on the main window?

Update: Thanks to AndrewS it turns out all I needed was to set IsUndoEnabled to false. Then the app commands get ignored and the top level window can handle them. Yay!

like image 653
scobi Avatar asked Oct 27 '11 17:10

scobi


1 Answers

You have to register a KeyBinding for the shortcut and associated it with the ApplicationCommands.NotACommand. e.g.

    <TextBox>
        <TextBox.InputBindings>
            <KeyBinding Key="Y" Modifiers="Control" Command="NotACommand" />
            <KeyBinding Key="Z" Modifiers="Control" Command="NotACommand" />
        </TextBox.InputBindings>
    </TextBox>
like image 160
AndrewS Avatar answered Sep 28 '22 06:09

AndrewS