M.C.
M.C.

Reputation: 1745

How to cancel a Context Menu Opened Event?

I want to cancel the Context Menu Opened Event of a TreeViewItem

private void ContextMenu_Opened(object sender, RoutedEventArgs e)
    {
        e.Handled = true;
    }

i thought this should work but instead i got a tiny context menu that has no menu items but i would like to have nothing appearing. Thanks

Upvotes: 9

Views: 10945

Answers (1)

dowhilefor
dowhilefor

Reputation: 11051

You should use the ContextMenuOpening event of the control that owns the context menu, which is fired right before the context menu opens. There you can change the context menu or suppress it. Your code for the event to suppress works if you use the Opening event, see this article for further infos.

Upvotes: 14

Related Questions