Hi,
I am using Infragistics 11.2 with Visual Studio 2010 and PRISM framework, a plug-in based architecture.
What I want is to show the context menu on the XamDataGrid and then through command binding I want to bind each menuItem to my ViewModel. I can do this easily as follow
<igDP:XamDataGrid.ContextMenu>
<ContextMenu>
<MenuItem Header="Item 1"
Command="{Binding MyCommand}"/>
</MenuItem>
</ContextMenu>
</igDP:XamDataGrid.ContextMenu>
But the problem is to bind the CommandParameter to the current record of the grid (on which I have Right Clicked for the contextMenu), Please note that I don’t want to select the record because selecting a record means something else to me and I do something different.
So what I tried is bellow
Command="{Binding MyCommand }"
CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type igDP:DataRecordPresenter}}, Path=Record.DataItem}">
But the parameter is null.
Then I set the ContextMenu on the DataRecordPresenter of the XammDataGrid, like.
<Style TargetType="{x:Type igDP:DataRecordPresenter}">
<Setter Property="ContextMenu">
<Setter.Value>
Command="{Binding RelativeSource=
{RelativeSource FindAncestor,
AncestorType={x:Type igDP:XamDataGrid}},
Path=DataContext.MyCommand}"
CommandParameter="{Binding RelativeSource=
{RelativeSource FindAncestor, AncestorType{x:Type igDp:DataRecordPresenter}},Path=Record}"/>
</Setter.Value>
</Setter>
</Style>
But the command is never invoked on the context menu and this is the actual problem. And I want to use the ContextMenu in the DataRecordPresenter, because I may use different contextmenu for different records in future.
Kindly help me to find out the problem with the context menu of the DataRecordPresenter that no command is being invoked, and the current record which I need to send to ViewModel without selecting it.
Thanks and regards
HI ,
I am reviewing your issue. The reason the bindings are not working is because the ContextMenu is not in the XamDataGrid's visual tree.
Sincerely, Matt Developer Support Engineer
HI,
Since you want to have different menu's per different DataRecordPresenters, I create a Style for the DataPresenter and bound its contentmenu to its datacontext (which contains the Record) and used a converter. In the converter i returned a different contextmenu.
Please review my attached sample.
Please let me know if you need further assistance regarding this issue.