您好! 我的问题是我正在编写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永远不会关闭
发布评论