Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
590
Different Context Menu For Different Type of Rows in XamDataGrid
posted

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

<igDP:XamDataGrid.ContextMenu>

<ContextMenu>                                            

<MenuItem Header="Item 1"

Command="{Binding MyCommand }"

CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type igDP:DataRecordPresenter}}, Path=Record.DataItem}">

</MenuItem>

</ContextMenu>

</igDP:XamDataGrid.ContextMenu>

 

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>

<ContextMenu>

<MenuItem Header="Item 1"

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}"/>                 

</MenuItem>

</ContextMenu>

</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