Is there a way to programatically close a menuitem in WPF

后端 未结 3 1344
执笔经年
执笔经年 2021-01-12 06:28

I have a menu in wpf that has an input box and a button on it. Once the user clicks the button I need to close the menu.

Is there a way to do this?

         


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-12 07:04

    Get hold of the MenuItem and do:

    _menuItem.IsSubmenuOpen = false;
    

    Easy way to get hold of it:

    Code-behind:

    _button.Click += delegate
    {
        (_button.Tag as MenuItem).IsSubmenuOpen = false;
    };
    

提交回复
热议问题