How to add Custom Commands to TreeView Context Menu

Hello,

I am trying to add a custom command to add a node to the treeview, but it's not binding. I set the data context to the view model that contains AddNodeCommand, but I keep getting a binding failure.

<sync:SfTreeView.ItemContextMenu>
                <ContextMenu>
                    <MenuItem Command="{Binding AddNodeCommand}" Header="Add Node"/>
                </ContextMenu>
</sync:SfTreeView.ItemContextMenu>


Any assistance with this would be much appreciated.



1 Reply 1 reply marked as answer

MA Mohanram Anbukkarasu Syncfusion Team January 14, 2022 08:24 AM UTC

Hi Nour, 

You can make the command to work properly by binding as shown below.  

<sync:SfTreeView.ItemContextMenu>
                <ContextMenu>
                    <MenuItem Command="{Binding Path=TreeView.DataContext.AddNodeCommand}" Header="Add Node"/>
                </ContextMenu>
</sync:SfTreeView.ItemContextMenu> 

We have prepared a simple sample to add context menu with custom command and it is available in the following link for your reference.  



Please let us know if you require any other assistance from us. 

Regards, 
Mohanram A. 


Marked as answer
Loader.
Up arrow icon