We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Custom Context Menu


I have not been able to find adequate explanation on how to implement a custom context menu for the nodes in my diagram only. Basically, what I'm trying to do is open a context menu only on right click on a node and not a connection etc. Also, I want to be able to remove a couple of items from the default menu and add a couple of my own. How is it recommended on going about this with the latest version of the library?

Thank you for any of your help.

5 Replies

KR Keerthivasan Ramamoorthy Syncfusion Team October 19, 2016 12:13 PM UTC

Hi Stratos, 
Requirement:” Need to Customize the ContextMenu for Nodes”. 
We have support to achieve your requirement and Provided a sample to represent this. Please refer to sample link as below. 
Sample Link:CustomContextMenu
Sample details: 
In sample, we have set the Diagram Menu as null. So the ContextMenu did not shown for Nodes and Connectors. We have customized the contextmenu for Nodes in the ItemSelectedEvent by disabling the InheritMenu Constraints for Nodes. 
Constraints and ContextMenu Behavior:  
Constraints are used to enable/disable certain behaviors of the SfDiagram, Node and Connector. The default value of Menu property for Node and Connector is null. So, the Default(SfDiagram) ContextMenu is shown for Nodes and Connectors. In order to Replace the ContextMenu for Nodes/Connectors, we have disable the InheritMenu Constraints and enable the Menu Constraints for Nodes/Connectors.   
For more details about ContetMenu customization, please visit our online help documentation from the below link.  
Documentation Link:  
Additional Information: 
In Volume 4 release, we have provided a DiagramMenuOpeningEvent support for Diagram to customize the ContextMenu and MenuItem for Nodes and Connectors. 
Keerthivasan R. 

SG Stratos Geroulis October 19, 2016 09:53 PM UTC

Thank you for your response.

I am using the classic Diagram (DiagramControl) and not SfDiagram. As I see it, the same logic does not really apply on it. Do you have a link to another example/article that achieves the same effect as the one you described for the SfDiagram?

Thanks again,

RA Ranjitha Amirthalingam Syncfusion Team October 20, 2016 01:35 PM UTC

Hi Stratos, 
Thanks for the update. 
We have achieved your requirement in Diagram Control (Classic). We have provided the sample to represent this. Please refer to the sample from the following link. 
Sample Link: Custom_Context_menu
We have support for enabling/disabling ContextMenu on Node and LineConnector. We have provided codesnippet to represent this. Please refer to the codesnippet as below.

//for enabling ContextMenu on Node 
diagramView.NodeContextMenu = new ContextMenu { Visibility = Visibility.Visible }; 
//for disabling ContextMenu on Node 
diagramView.NodeContextMenu = new ContextMenu { Visibility = Visibility.Collapsed }; 
Here, diagramView is the instance of DiagramView. 

Ranjitha A. 

SG Stratos Geroulis October 20, 2016 08:46 PM UTC

Thank you very much, this did the trick!

RA Ranjitha Amirthalingam Syncfusion Team October 21, 2016 08:54 AM UTC

Hi Stratos,   
Thanks for your update.  
Please let us know if you require further assistance on this.  
Ranjitha A.  

Live Chat Icon For mobile
Up arrow icon