gpt4 book ai didi

.net - 为什么单击其背景区域时 WPF 弹出窗口会关闭?

转载 作者:行者123 更新时间:2023-12-03 11:35:27 24 4
gpt4 key购买 nike

我有一个 WPF Popup包含一些编辑控件(列表框、文本框、复选框)的控件,布局中有相当多的空白。
Popup.StaysOpen设置为 False ,这是必需的。如果用户单击应用程序中的其他位置,则应认为编辑操作已中止,弹出窗口应关闭。

不幸的是,每当用户在弹出窗口的背景区域(编辑控件之间的空间)内单击时,弹出窗口也会关闭。

我试过将弹出窗口设置为 Focusable .我还尝试将弹出窗口的 child (Border)设置为可聚焦。两方面都没有运气。

此外,鼠标事件似乎通过弹出窗口隧道。当我单击它时,弹出窗口下方的任何元素都会成为焦点。尽管 PopupBorder (我正在点击)同时拥有 IsHitTestVisibleFocusable设置为 true .

最佳答案

最后,我发现以下方法有效。鉴于...

<Popup x:Name="_popup"
StaysOpen="False"
PopupAnimation="Slide"
AllowsTransparency="True">

...我在调用 InitializeComponent 后在构造函数中使用了这段代码...
// Ensure that any mouse event that gets through to the
// popup is considered handled, otherwise the popup would close
_popup.MouseDown += (s, e) => e.Handled = true;

关于.net - 为什么单击其背景区域时 WPF 弹出窗口会关闭?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/619798/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com