Disable the Default Undo Behavior on the SwitchableSyntaxEditor

SyntaxEditor for WPF Forum

Posted 4 years ago by iyu - New York, NY
Version: 17.1.0652

Dear Support,

Is there any way to disable the default undo behavior of the syntax editor? Currently, I'm using the SwitchableSyntaxEditor and use the Text property to bind a string variable in my view model. I have a custom undo command to handle the undo in the view model. However, when I use the ctrl-z shortcut to call my undo command on the Text property, my custom undo command is overridden by the Text property's default undo behavior and don't get called. The only way to enable my custom undo command is to click on other text fields and use ctrl-z. I can use my custom command if I click on the undo button directly on the view. Please help me to fix the problem.


This is the code in my view:

<dxlc:LayoutItem Label="{Binding SomeLabel, UpdateSourceTrigger=PropertyChanged}" Visibility="{Binding IsVisible, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource VisibleIfFalse}}">

    <views:SwitchableSyntaxEditor x:Name="ImplementsSyntaxEditor" IsTextDataBindingEnabled="True" Text="{Binding T.SomeText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsMultiLine="False" ScriptingLanguage="{Binding T.SomeLanguage, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" FontFamily="Segoe UI"/>


Comments (2)

Answer - Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA


As the SyntaxEditor is being initialized, we set up these input bindings:

this.InputBindings.Add(new KeyBinding(EditorCommands.Redo, VKey.Y, ModifierKeys.Control));
this.InputBindings.Add(new KeyBinding(EditorCommands.Redo, VKey.Z, ModifierKeys.Control | ModifierKeys.Shift));
this.InputBindings.Add(new KeyBinding(EditorCommands.Undo, VKey.Z, ModifierKeys.Control));

If you scan through the InputBindings collection and remove any KeyBindings that use Redo/Undo commands, I think that will block our default undo logic from being key bound. 

You also will want to iterate the CommandBindings collection and remove any command bindings for the ApplicationCommands.Redo and ApplicationCommands.Undo commands to make sure those aren't handled by our control at all (if bound to a menu, etc.).

Actipro Software Support

Posted 4 years ago by iyu - New York, NY

Thanks for your hint. I already figure out the solution.


            for (int i = 0; i < SyntaxEditor.InputBindings.Count; i++)
                var inputBinding = SyntaxEditor.InputBindings[i] as KeyBinding;
                if (inputBinding != null)
                    if (((inputBinding.Modifiers == ModifierKeys.Control) && (inputBinding.Key == Key.Z)) || ((inputBinding.Modifiers == ModifierKeys.Control) && (inputBinding.Key == Key.Y)))
            for (int i = 0; i < SyntaxEditor.CommandBindings.Count; i++)
                var commandBinding = SyntaxEditor.CommandBindings[i] as CommandBinding;
                if (commandBinding != null)
                    if (commandBinding.Command == ApplicationCommands.Undo || commandBinding.Command == ApplicationCommands.Redo)

[Modified 4 years ago]

The latest build of this product (v21.1.2) was released 20 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.