I am trying to add a context menu to an Xceed extended WPF datagrid. I am able to show the context menu and the commands fire from the menu, but right clicking on a row does not set it as the selected row and so the wrong record is used by the command.
Is there a way to change the way the selected item is set so that it can be updated by right click?
<xcdg:DataGridControl ItemsSource="{Binding Source={StaticResource RecordsForList}}" SelectedItem="{Binding SelectedRecord}">
<xcdg:DataGridControl.ContextMenu>
<ContextMenu>
<MenuItem Command="{Binding OpenCommand}" Header="Open" />
</ContextMenu>
</xcdg:DataGridControl.ContextMenu>
</xcdg:DataGridControl>
Instead of changing the way selecting an item works, you could pass the current item as a command parameter to the command if you set the
ContextMenuproperty of each individualDataRow:The other option would be to write some code in the view that actually selects an item on right-click, e.g.: