Hello,
in a XamDatagrid I have defined a contextmenu for one field. By rightclicking on a cell I was expecting that the SelectedDataItem would be updated to this record, that is hit by the right mouse click.
This is not the case. I need to left click = select explicit first and then open the contextmenu.
Can you please advice if this is the best way to ensure that on rightclick = contextmenu opeing the hit record is the SelectedDataItem? Maybe there is a better method to prevent the multiple castings in the code behind.
Current XAML and code behind snipped below.
Thanks
Niko
<Style x:Key="BaustellenStyle" TargetType="{x:Type igDP:CellValuePresenter}" BasedOn="{StaticResource {x:Type igDP:CellValuePresenter}}"> <EventSetter Event="MouseRightButtonDown" Handler="Baustelle_RightMouseButtonDown" /> <Setter Property="ContextMenu" Value="{StaticResource BaustellenContextMenu}"/> </Style>
private void Baustelle_RightMouseButtonDown(object sender, MouseButtonEventArgs e)
{ var x = sender as CellValuePresenter; var y = x.DataContext as DataRecord; var z = y.DataItem as AuslastungsBaustelle; this.Auslastungsplanung.SelectedDataItem = z; }
Hello Nikolaus,
I have been investigating into this behavior, and the XamDataGrid will not select rows on right-click by default. As such, if you are trying to ensure that the SelectedDataItem is the cell that you right-clicked, I would recommend using a method like the one you have provided in your code-snippet.
Please let me know if you have any other questions or concerns on this matter.