Custom ContextMenu for diagram node

I try create custom context menu.

How can I add in this menu a delete operation from standard menu?
I create custom function and run this code : this.diagramModel.Nodes.Remove(sender). Node delete but event NodeDeleted doesn't call.

Any advice please.

1 Reply

RT Ramya Thirugnanam Syncfusion Team September 17, 2018 10:58 AM UTC

Hi Hanish, 
Please find the responses to your queries as below. 
S. No 
Query 
Response 
 
How can I add in this menu a delete operation from standard menu? 
It is by design ContextMenu for a Node will be created only when the Node is right clicked. So new custom ContextMenuItems can be added to the default ones as shown in the following code example.

Code example:

 
//Register the Evnet 
 
node.MouseRightButtonUp += new MouseButtonEventHandler(node_MouseRightButtonUp); 
 
//Event for MouseRightButtonUp 
 void node_MouseRightButtonUp(object sender, MouseButtonEventArgs e) 
  { 
       //Get the default context menu. 
       ContextMenuControl menu = (sender as Node).ContextMenu; 
       ContextMenuControlItem createNodeContextMenuItem = new ContextMenuControlItem(); 
       createNodeContextMenuItem.Header = "Delete"; 
 
        //Add new customer context menu item. 
        menu.Items.Add(createNodeContextMenuItem); 
        createNodeContextMenuItem.Click += new RoutedEventHandler(createNodeContextMenuItem_Click); 
 
        //Unregister the Event 
        (sender as Node).MouseRightButtonUp -= new MouseButtonEventHandler(node_MouseRightButtonUp); 
 
 } 
 
 //MenuClick evnet 
 void createNodeContextMenuItem_Click(object sender, RoutedEventArgs e) 
 { 
     //Do Something 
 } 
 

Here, node refers to the instance of the Node.
 
2.  
 this.diagramModel.Nodes.Remove(sender). Node delete but event NodeDeleted doesn't call. 
“DiagramModel.Nodes.Remove(node)” will invoke the NodeDeleted event of the DiagramView. Please verify whether the “NodeDeleted” event is registered before the code to remove the Node. 
 
Please provide us the sample or description of Diagram usage to represent your application scenario. This will help us to investigate further on the reported issue. 
 
Regards, 
Ramya T 


Loader.
Up arrow icon