Live Chat Icon For mobile
Live Chat Icon

How do I listen to click events on all the MenuItems through the parent ContextMenu?

Platform: WPF| Category: Context Menu

Instead of setting up event handlers on all the MenuItems you can listen to those events as they bubble up to the context menu as follows:



Or you can setup the same thing in code as follows:

menuItem1.AddHandler(MenuItem.ClickEvent, new RoutedEventHandler(MnItem_Click));

The event handler would then be something like:

private void MnItem_Click(object sender, RoutedEventArgs e)
	MenuItem item = e.Source as MenuItem;

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.