avoid remove nodes with cancel key

3 posts, 0 answers
  1. Fabrizio
    Fabrizio avatar
    9 posts
    Member since:
    Nov 2012

    Posted 04 Dec 2012 Link to this post

    hi all, hope u can help me, i tried this code but the event is never fired

     <telerik:RadDiagram x:Name="diagram"
                                ShapeStyle="{StaticResource TestNodeStyle}"

     private void diagram_KeyDown(object sender, KeyEventArgs e)
                if (e.Key == Key.Cancel)
                    e.Handled = true;

  2. Tina Stancheva
    Tina Stancheva avatar
    3299 posts

    Posted 07 Dec 2012 Link to this post

    Hello Fabrizio,

    The KeyDown and PreviewKeyDown events are handled internally by the RadDiagram. This is why if you need to customize their default logic, you'll have to add their handlers in code behind, specifying that you need your custom handlers to be executed even if the events are already handled by someone else:
    this.AddHandler(RadDiagram.KeyDownEvent, new KeyEventHandler(OnDiagramKeyDown), true);

    Also, in order to handle a delete event triggered by the keyboard, you'll have to handle the PreviewKeyDown event rather than the KeyDown event. And if you'd like to deny any delete operation on the shapes, you can set the RadDiagramShape.AllowDelete property to False. You can also disable the delete operation on the entire diagram object by setting the RadDiagram.AllowDelete property to False.

    I attached a sample solution demonstrating how to disable a Delete key deletion of a shape/connection. Let me know if it helps.

    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. Fabrizio
    Fabrizio avatar
    9 posts
    Member since:
    Nov 2012

    Posted 07 Dec 2012 Link to this post

    AllowDelete is what i need.

Back to Top