找出文本框失去焦点的原因
文本框失去焦点,我不知道为什么。如何找出焦点丢失的原因?我尝试监听 TextBox.LostFocus 事件,但它的参数似乎没有给我任何有关原因的有价值的信息。
A textbox looses focus and I don't know why. How can I find out the reason of why the focus is lost? I've tried listening to TextBox.LostFocus event, but it's parameters don't seem to give me any valuable information about the cause.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试 Snoop - 一种监听应用中所有事件的工具。
您还可以尝试使用 Visual Studio 调试应用程序,在 TextBox.LostFocus 事件处理程序中设置断点,然后检查调用堆栈,您可能会在其中看到哪个方法导致失去焦点。
You might try Snoop - a tool that listens to all events in your app.
You could also try to debug your app with Visual Studio, set a breakpoint in TextBox.LostFocus event handler, and inspecting the call stack, where you might see which method caused the lost focus.
我最好的猜测是它正在失去焦点,因为其他东西占据了焦点
。您可以使用 FocusManager 来找出当前拥有焦点的控件。例如,以下代码行将返回包含
MainWindow
焦点的控件My best guess is it is losing focus because something else takes the focus
You can use the
FocusManager
to find out what control currently has focus. For example, the following line of code will return the control that contains focus for theMainWindow