Show menu programmatically in WPF Show menu programmatically in WPF wpf wpf

Show menu programmatically in WPF


Get hold of the menu item, and do this :

_menuItem.IsSubmenuOpen = true;


Check out this example on how to open a context menu.

http://www.uxpassion.com/2009/01/how-to-enable-and-show-context-menu-on-left-click-in-wpf/

In summary

You can just call:

YourContextMenu.IsOpen = true;

This will display the context menu, just make sure its associated with a FrameworkElement on which it is displaying)


private void button_Click(object sender, RoutedEventArgs e){    var button= sender as FrameworkElement;    if (button != null)    {        button.ContextMenu.IsOpen = true;    }}