Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 827
M.C. Avatar asked Aug 10 '11 23:08

M.C.


People also ask

How do you handle context menu?

The contextmenu event fires when the user attempts to open a context menu. This event is typically triggered by clicking the right mouse button, or by pressing the context menu key.

What is Contextmenu in JavaScript?

When we click the right mouse button on our desktop, a menu-like box appears and this box is called the context menu. In JavaScript, a context menu event runs when a user tries to open a context menu. This can be done by clicking the right mouse button.


1 Answers

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.

like image 80
dowhilefor Avatar answered Sep 21 '22 04:09

dowhilefor