单击某个位置超出界限时如何阻止菜单关闭

时间:2022-08-26 20:14:29

When I open the menu, and after that click somewhere in the window the menu is closing, how can I prevent it from being closed ?

当我打开菜单,然后在窗口中的某个位置点击菜单关闭时,如何防止它被关闭?

this is my XAML-

这是我的XAML-

<Grid>
    <Menu Height="40" VerticalAlignment="Top">
        <Menu.Items>
            <MenuItem Header="file">
                <MenuItem Header="Save"/>
            </MenuItem>
        </Menu.Items>
    </Menu>
</Grid>

单击某个位置超出界限时如何阻止菜单关闭

1 个解决方案

#1


0  

I believe you would have to re-template the Menu control so that its Popup has StaysOpen="true". I don't believe Menu exposes any property that its template binds to in order to allow you to control this without the need for re-templating. Alternatively, you could hack together a solution that searches for the Popup in the visual tree and injects the desired property value.

我相信您必须重新模板Menu控件,以使其Popup具有StaysOpen =“true”。我不相信Menu会公开其模板绑定的任何属性,以便您无需重新模板即可控制它。或者,您可以将在可视树中搜索Popup的解决方案混合在一起并注入所需的属性值。

But, really, I think you should think about alternative solutions altogether. This is a pretty radical departure from the normal expected behavior of menus, and such a radical departure would require radical impetus.

但是,实际上,我认为你应该完全考虑替代解决方案。这与菜单的正常预期行为完全不同,这种彻底的离开需要激进的推动力。

#1


0  

I believe you would have to re-template the Menu control so that its Popup has StaysOpen="true". I don't believe Menu exposes any property that its template binds to in order to allow you to control this without the need for re-templating. Alternatively, you could hack together a solution that searches for the Popup in the visual tree and injects the desired property value.

我相信您必须重新模板Menu控件,以使其Popup具有StaysOpen =“true”。我不相信Menu会公开其模板绑定的任何属性,以便您无需重新模板即可控制它。或者,您可以将在可视树中搜索Popup的解决方案混合在一起并注入所需的属性值。

But, really, I think you should think about alternative solutions altogether. This is a pretty radical departure from the normal expected behavior of menus, and such a radical departure would require radical impetus.

但是,实际上,我认为你应该完全考虑替代解决方案。这与菜单的正常预期行为完全不同,这种彻底的离开需要激进的推动力。