I'm using a code for get the name of the control that fire the ContextMenu, but the compiler return this message on this line: ContextMenu menu = menuItem.GetContextMenu();
MenuItem does not contain a definition of GetContextMenu and found no extension method 'GetContextMenu' accepting a first argument of type 'MenuItem'. Probably missing a using directive or an assembly reference.
The same error here:
Control sourceControl = menu.SourceControl;
This is my method:
private void ClearTable_Click(object sender, RoutedEventArgs e)
{
// Try to cast the sender to a MenuItem
MenuItem menuItem = sender as MenuItem;
if (menuItem != null)
{
// Retrieve the ContextMenu that contains this MenuItem
ContextMenu menu = menuItem.GetContextMenu();
// Get the control that is displaying this context menu
Control sourceControl = menu.SourceControl;
}
}
Which library I must to add?