WPF 文本框中的 GotFocus 和 LostFocus 事件
我在 WPF 窗口中有一个文本框控件。我有单独的 GotFocus 和 LostFocus 事件处理程序。但是当文本框第一次获得焦点时,LostFocus会在GotFous之后调用(文本框第一次获得焦点后就会失去焦点)。但是当文本框第二次获得焦点时,这种情况不会发生。
I have a textBox control in a WPF window. I have separate handlers for GotFocus and LostFocus events. But when the textbox attains focus for the first time LostFocus is invoked after GotFous (The textbox loses focus as soon as it attains focus for the first time) . But this doesn't happen when the textBox attains focus for the second time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来好像在 GotFocus 事件处理程序(或调用堆栈的更深处)期间发生了某些事情,将焦点放弃给另一个控件。
您可能想尝试在 LostFocus 事件处理程序中设置断点,然后查看调用堆栈以查看是否有某些内容直接或间接在其他地方设置了焦点。
Sounds like maybe something is happening during the GotFocus event handler (or deeper in the call stack) that is relinquishing focus to another control.
You might want to try setting a breakpoint in your LostFocus event handler and then look at the call stack to see if something is setting the focus elsewhere either directly or indirectly.