Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Menu item opening and closing event

I want to handle an event, whenever the Submenus of a menu item opens. Same for closing. how can I do this?

like image 599
jawahar Avatar asked Feb 18 '10 08:02

jawahar


2 Answers

Very easy. Subscribe to a MenuItem's SubmenuOpened event. Traditional way to do it:

MidItem.SubmenuOpened += new RoutedEventHandler(MidItem_SubmenuOpened);

private void MidItem_SubmenuOpened(object sender, RoutedEventArgs e)
{
    //Menu Open Logic Here
}

Or the cool dynamic method:

MidItem.SubmenuOpened += delegate(object sender, RoutedEventArgs e)
{
    //Menu Open Logic Here
};
like image 193
sidney.andrews Avatar answered Nov 20 '22 04:11

sidney.andrews


Not sure what you want, but take a look at these events for ContextMenu and MenuItem:

ContextMenu:

http://msdn.microsoft.com/en-us/library/system.windows.controls.contextmenu_events.aspx

MenuItem:

http://msdn.microsoft.com/en-us/library/system.windows.controls.menuitem_events.aspx

I think ContextMenuOpening and ContextMenuClosing might be interesting ;)

like image 44
Arcturus Avatar answered Nov 20 '22 03:11

Arcturus