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

avoid remove nodes with cancel key

2 Answers 93 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Fabrizio
Top achievements
Rank 1
Fabrizio asked on 04 Dec 2012, 12:51 PM
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 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 07 Dec 2012, 12:47 PM
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.

0
Fabrizio
Top achievements
Rank 1
answered on 07 Dec 2012, 02:55 PM
AllowDelete is what i need.

thanks.
Tags
Diagram
Asked by
Fabrizio
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Fabrizio
Top achievements
Rank 1
Share this question
or