I have a DataGrid with a ContextMenu. What I would like is when the context menu is brought up (via a right click), I want to get column data on the selected row. This data will be used to confirm whether or not some context menu options should be enabled or not.
So I tried the MouseRightButtonUp event handler, but I ended up getting a NullReferenceException.
<DataGrid MouseRightButtonUp="DataGrid_MouseRightButtonUp">
private void DataGrid_MouseRightButtonUp(object sender, MouseButtonEventArgs e) {
MessageBox.Show(((DataRowView)DataGrid.SelectedItem).Row.ItemArray[0].ToString());
}
I then tried the SelectionChanged event which ended up working however, it would not work more than once on a row if it was selected more then once. I need it such that for every time a row is right clicked, the event will fire off and return the column data. Also this event fired off on left clicks which are not needed.
What are my available options at this point?