防止 WPF 中 Menu 控件的菜单关闭 [英] Prevent menus of a Menu control in WPF from closing

查看:47
本文介绍了防止 WPF 中 Menu 控件的菜单关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们点击他的区域时,我试图阻止关闭 Wpf 中 Menu 控件的 Menus.

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...

有人知道如何在 Wpf 中实现这一点吗?

Anyone know how to achieve this in Wpf?

提前致谢!

推荐答案

有一个类似问题可用,这里是发布的解决方案:

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>

这篇关于防止 WPF 中 Menu 控件的菜单关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆