WFP Grid: MouseRightButtonDown firing occuring BEFORE SelectionChanged on grid. Causing syncing issue

I have a situation where I’m building a context menu for a right mouse button click on a datagrid. The menu’s content is based on the ‘selected row’. However when I right click a NEW row, the MouseRightButtonDown event is firing (and building the context menu) BEFORE the SelectionChanged event fires, which means the context menu is being built for the prior row’s data context.

Is there a way to avert this? Force the MouseRightButtonDown to wait for the SelectionChanged to occur?

Should I use a task delay? That seems hokey.

Here’s the code in question:

private async void Grid_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
//build context menu using "Grid.SelectedItem"


private async void Grid_SelectionChanged(object sender, SelectionChangedEventArgs e)

//process logic for item changing


Leave a Comment