Show menu programmatically in WPF

后端 未结 4 1827
名媛妹妹
名媛妹妹 2020-12-17 09:57

How can I open menu (System.Windows.Controls.Menu) programmatically in WPF?

相关标签:
4条回答
  • 2020-12-17 10:23
    private void button_Click(object sender, RoutedEventArgs e)
    {
        var button= sender as FrameworkElement;
        if (button != null)
        {
            button.ContextMenu.IsOpen = true;
        }
    }
    
    0 讨论(0)
  • 2020-12-17 10:25

    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)

    0 讨论(0)
  • 2020-12-17 10:30

    Get hold of the menu item, and do this :

    _menuItem.IsSubmenuOpen = true;
    
    0 讨论(0)
  • 2020-12-17 10:46
    void CmsBox_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        box = sender as WpfBox;
        ContextMenu cms = new ContextMenu();
        e.Handled = true;
        ...
    }
    
    0 讨论(0)
提交回复
热议问题