WPF Popup永远不会关闭 [英] WPF Popup Never Closes

查看:1530
本文介绍了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永远不会关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆