Is there a way to enable/disable the MenuItem of a ContextMenu depending on a value of the row being selected/right-clicked?
Hello PMac,
Thank you for posting in our forums!
You can handle the XamDataGrid's ContextMenuOpening event and edit the MenuItems from there.
Below, you can see a C# code snippet of how to achieve this.
private void XamDataGrid_ContextMenuOpening(object sender, ContextMenuEventArgs e) { DataRecordPresenter drp = Utilities.GetAncestorFromType((DependencyObject)e.OriginalSource, typeof(DataRecordPresenter), true) as DataRecordPresenter; DataRecord dr = drp.Record as DataRecord; Cell cell = dr.Cells["Name"]; if (cell != null) { XamDataGrid xdg = sender as XamDataGrid; MenuItem deleteMenuItem = xdg.ContextMenu.Items[2] as MenuItem; deleteMenuItem.IsEnabled = ("Computer" != cell.Value.ToString()); } }
If you have any further questions or concerns with this, please let me know and I will be glad to help.
Sincerely,Michael H.Software DeveloperInfragistics, Inc.www.infragistics.com/support