Prevent menus of a Menu control in WPF from closin

2019-05-24 03:37发布

I am trying to prevent the closing of the Menus of a Menu control in Wpf when we click out of his area.

My objective is if we for example have a Menu control in the top of the window. We then open any of the menus, and if we click somewhere in the window, the Menu closes. That is what I am wanting to prevent from happening.

What I want is only when the click happens on one of the Menu items, or in its header then the Menu can close...

Anyone know how to achieve this in Wpf?

Thanks in advance!

2条回答
The star\"
2楼-- · 2019-05-24 04:11

There is a similar question available, here is the solution posted:

<ContextMenu StaysOpen="True">  
    <MenuItem Header="Expand the clicking Area" StaysOpenOnClick="True">
        <MenuItem x:Name="AreaWhereClickingWillHappen" StaysOpenOnClick="True">
            <MenuItem.Header>
                <Control x:Name="The one with the clicking stuff" />
            </MenuItem.Header>
        </MenuItem>
    </MenuItem>
</ContextMenu>
查看更多
Summer. ? 凉城
3楼-- · 2019-05-24 04:15

Just set the StaysOpen property to true

查看更多
登录 后发表回答