This is a migrated thread and some comments may be shown as answers.

Overriding Diagram Commands

1 Answer 172 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 20 Jan 2017, 10:17 PM

I'm trying to remove the built-in binding of the ESC key to the DiagramCommands.CancelEdit command. I've tried both approaches outlined here:

http://www.telerik.com/forums/override-keyboard-copy-paste-controls

with no success. The first approach successfully registers a new command, but the existing default command is still executed. I need to remove that default behavior.

Both the InputBindings and CommandBindings collections are empty after the diagram has been loaded, so I'm assuming that these default command handlers are stored elsewhere?

Am I approaching this the right way, or is there an easier way to handle this requirement?

 

 

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 23 Jan 2017, 08:51 AM
Hello David,

The approaches from the forum could be used to override the default CancelEdit command. However, there is additional logic in the diagram that kicks-in and cancels the editing. Basically, when the KeyDown event is executed the selected shape is de-selected and this changes its IsInEditMode property to False. In order to cancel the edit cancellation action you can do two things:
  1. Override the CancelEdit command as demonstrated in the Override Diagram Command help article. Or set empty key binding on the escape command as Zarko demonstrated in the forum.
    CommandManager.RegisterClassInputBinding(typeof(RadDiagram), new InputBinding(ApplicationCommands.NotACommand, new KeyGesture(Key.Escape)));
  2. Then you can override the PreviewKeyDown event of RadDiagram and if the Esc key is pressed and if the selected shape is in edit mode handle the event. This will ensure that the shape won't be de-selected when in edit mode.
    void diagram_PreviewKeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Escape && this.diagram.SelectedItem != null)
        {
            var selectedItem = (RadDiagramShape)this.diagram.SelectedItem;
            if (selectedItem.IsInEditMode)
            {
                e.Handled = true;
            }
        }
    }
I hope this helps.

Regards,
Martin
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
Diagram
Asked by
David
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or