I am new in WPF programming with MVVM pattern. Now I have added the context menu in the datagrid. But, when I click the right mouse button, I don\'t know how to get the sele
bigworld12 has close to the right answer here, but it breaks if your context menu is templated. Try:
DataGridRow row =
((sender as MenuItem)?.GetAncestors()
?.FirstOrDefault(dpo => dpo.GetType() == typeof(ContextMenu)) as ContextMenu)
?.PlacementTarget as DataGridRow;
for the code-behind. I used nullable operators in case you somehow get here without the expected parent tree and target (maybe by triggering the context menu while off the grid.)