WPF Popup永远不会关闭

编程入门 行业动态 更新时间:2024-10-27 05:23:59
本文介绍了WPF Popup永远不会关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好! 我的问题是我正在编写UserControl。基本上是一个文本框,当它获得焦点时,它会打开一个弹出窗口。弹出窗口包含按钮,网格等。弹出窗口还将其StaysOpen属性设置为False,并且在文本框previewmousedown事件中将IsOpen设置为true。 事情是,一旦我单击文本框,它就会打开但是当我在弹出窗口外面点击时它没有关闭。 一个奇怪的行为是当我点击弹出窗口内的一个按钮然后在它之外时,它正常工作。它关闭。 我做错了什么?

Hello! My problem is that I am coding a UserControl. Is basically a textbox that when it get focus it opens a popup. The popup contains buttons, a grid and others. The popup also has its StaysOpen property to False and the IsOpen is set to true on the textbox previewmousedown event. The thing is that once I click the textbox it opens but when I click outside the popup it does not close. A strange behavios is that when I click a button inside the popup and then outside of it, it works normally. It closes. What am I doing wrong?

推荐答案

弹出窗口可能无法获得焦点当它显示。当它失去焦点时执行关闭动作,但如果你没有首先获得它,你就不会失去焦点。 作为一种解决方案,您可能希望将重点放在弹出窗口上。当您点击弹出窗口上的按钮时,您也可以手动对焦。 祝您好运! The popup probably doesn't get focus when it is shown. The close action is performed when it looses its focus, but you cannot lose focus if you didn't get it in the first place. As a solution you might want to set the focus on the popup. When you click the button on the popup you also give it focus but manually. Good luck!

设置此 <Popup StaysOpen="False" />

更多推荐

WPF Popup永远不会关闭

本文发布于:2023-10-06 19:40:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1467626.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:永远不会   WPF   Popup

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!