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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

how can ContextMenu command bind to ViewModel in MVVM style?

Thread ID:





119959 Aug 18,2015 05:57 PM UTC Aug 19,2015 02:18 PM UTC WPF 1
Tags: SfDataGrid
Tommie Chen
Asked On August 18, 2015 05:57 PM UTC


I want to bind SfDataGrid ContextMenu MenuItem to a command from my viewmodel.  It doesn't work. I see the syncfusion sample code are using static command. Could you provide a sample which is not using static command?  Here is my code below,  Could you advice why this is not working? 

                <ContextMenu Style="{x:Null}">
                    <MenuItem  Command="{Binding Path=DataContext.ShowParameterDetailCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
                                      Header="Show Details">

C# side(use PRISM DelegateCommand):

this.ShowParameterDetailCommand = new DelegateCommand<object>(this.ShowParameterDetail);

public ICommand ShowParameterDetailCommand { get; private set; }

        private void ShowParameterDetail(object obj)

Jai Ganesh S [Syncfusion]
Replied On August 19, 2015 02:18 PM UTC

Hi Tommie,

Thank you for contacting Syncfusion Support.

We have analyzed your query with your code snippet. In that the DataContext is not set for ContextMenu items. Hence the context menu is not worked as expected. However you can achieve your requirement for binding the SfDataGrid ContextMenu MenuItem to a command from my viewmodel by setting Source for Context Menu Item,

Code Snippet [XAML]:


           <ContextMenu Style="{x:Null}">

              <MenuItem Command="{Binding CopyCommand,Source={StaticResource employeeInfoViewModel}}" Header="Copy"></MenuItem>




CopyCommand = new ContextMenuDemo.ContextMenuCommands.RelayCommand(ShowMessage);

private ICommand copyCommand;

public ICommand CopyCommand




       return copyCommand;




       copyCommand = value;



public void ShowMessage(object obj)


      //Do your actions here


We have also prepared the sample based on this which is available from the below location,

Sample: http://www.syncfusion.com/downloads/support/directtrac/142870/ze/ContextMenuDemo-1972320366

Please let us know if you need further assistance.

Thank you,

Jai Ganesh S


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon