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"
                                Grid.Row="1"
                                ActiveTool="PanTool"
                                ShapeStyle="{StaticResource TestNodeStyle}"
                                KeyDown="diagram_KeyDown"/>

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

    thanks,
  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 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.

    Regards,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Fabrizio
    Fabrizio avatar
    9 posts
    Member since:
    Nov 2012

    Posted 07 Dec 2012 Link to this post

    AllowDelete is what i need.

    thanks.
Back to Top