Menu open and close event

I want to handle the event when a menu submenu opens. The same for closing. How can i do this?

+6
source share
2 answers

Very easy. Sign up for the MenuItem SubmenuOpened MenuItem . The traditional way to do this is:

 MidItem.SubmenuOpened += new RoutedEventHandler(MidItem_SubmenuOpened); private void MidItem_SubmenuOpened(object sender, RoutedEventArgs e) { //Menu Open Logic Here } 

Or a cool dynamic method:

 MidItem.SubmenuOpened += delegate(object sender, RoutedEventArgs e) { //Menu Open Logic Here }; 
+12
source

Not sure what you want, but 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;)

+1
source

Source: https://habr.com/ru/post/1301672/


All Articles