ContextMenu.StaysOpen 属性 (WPF)

发布于 2024-07-29 23:59:15 字数 612 浏览 1 评论 0原文

这里有一个简单的问题: 的作用是什么ContextMenu(或等效的Popup)控件的 StaysOpen 属性实际上有何作用? 我曾尝试观察行为上的差异,但我什么也没注意到。

MSDN 声明如下:

如果菜单应保持打开状态直到 IsOpen 属性更改为 false,则为 true; 否则为假。 默认为 false。

然而,这确实很模糊,对我没有任何帮助。 我之前猜测只有当 IsOpen 从代码中设置为 false 时才会关闭弹出窗口 - 而不是当它失去焦点/鼠标捕获(我想要的行为)时才会关闭,但情况似乎并非如此。

有人可以解释一下这个属性到底是做什么用的吗? 理想情况下,通过一个例子来确定行为差异是最有帮助的。 最后,如果您对我如何获得所需的行为有任何建议,那就太好了。

Simple question here: what does the StaysOpen property of the ContextMenu (or equivalently Popup) control actually do? I have tried observing the difference in behaviour, but I notice none whatsoever.

MSDN states the following:

true if the menu should stay open until the IsOpen property changes to false; otherwise, false. The default is false.

However, this is really quite vague, and is of no help to me. I was previously guessing that the popup would only be closed when IsOpen is set to false from code - and not when it loses focus/mouse capture (my desired behaviour), but this seems to not be the case.

Could someone please explain what exactly this property is meant to do? Ideally, an exampe identify that difference in behaviour would be most helpful. Finally, if you have any suggestions how I might get my desired behaviour, that would be great.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

救星 2024-08-05 23:59:15

似乎答案是,因为 ContextMenu 捕获了鼠标,所以弹出窗口不可避免地会关闭,因为当鼠标失去捕获时,控件会自动连接以关闭弹出窗口。 也许是设计缺陷? 然而,似乎可以通过使用原始的 Popup 控件或适当时的 ToolTip 来克服这个问题。

Seems like the answer is that because ContextMenu captures the mouse, the popup inevitably closes because the control is automatically wired to close the popup when the mouse loses capture. A design flaw, perhaps? It seems that it can however be overcome by using a primitive Popup control, or a ToolTip when appropiate.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文