Hello,
I have a the following code (Code #1) attached to a XamDataGrid:
<ig:ContextMenuManager> <ig:ContextMenuManager.ContextMenu> <ig:XamContextMenu> <ig:XamMenuItem Header="Edit"> <i:Interaction.Triggers> <i:EventTrigger EventName="Click"> <i:InvokeCommandAction Command="{Binding Path=MyCommand}" /> </i:EventTrigger> </i:Interaction.Triggers> </ig:XamMenuItem> </ig:XamContextMenu> </ig:ContextMenuManager.ContextMenu></ig:ContextMenuManager>where xmlns:ig="http://schemas.infragistics.com/xaml" xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"The command does not work as intended, nothing is being shown.The following code (Code #2) works as intended:<Button Content="Save" Height="20"> <i:Interaction.Triggers> <i:EventTrigger EventName="Click"> <i:InvokeCommandAction Command="{Binding Path=MyCommand}"/> </i:EventTrigger> </i:Interaction.Triggers> </Button>When I change MyCommand in Code #2 to MyCommand2 (which doesn't exist) it tries to find the property MyCommand2 on the DataContextMyCommand does actually exist on the DataContext (as shown on Code #2)The command actually isprivate ICommand _myCommand;public ICommand MyCommand{ get { return _myCommand ?? (_myCommand = new RelayCommand(param => MessageBox.Show("TEST!"))); } }I'm using the MVVM architecture.Why doesn't the Code #1 work? Any ideas?Thank you!
You're right. It looks like the InvokeCommandAction Behavior fails to work in a XamMenuItem in a XamContextMenu. I've reported this as a bug and it is assigned Case ID: CAS-63623-2YJ4B9.
I apologize for the inconvenience!
I spoke with development on this issue.
A xamContextMenu isn't in the VisualTree, and thus doesn't partake in the DataContext inheritance. The wpf Contextmenu will work because it is in the visualTree.
To get this to work, your binding would need a Source set to a StaticResource for the command.
Valerie