Overriding Diagram Commands

2 posts, 1 answers
  1. David
    David avatar
    3 posts
    Member since:
    Mar 2015

    Posted 20 Jan Link to this post

    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:


    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?




  2. Answer
    Martin Ivanov
    Martin Ivanov avatar
    1444 posts

    Posted 23 Jan Link to this post

    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.

    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.
Back to Top