WPF 用户控件不允许在单独的控件上更改丢失焦点
这个问题解释起来有点棘手。
我有一个带有一些文本框的用户控件。我在同一窗口中的该用户控件上方还有一个菜单。每当我离开时,LostFocus 都会在文本框上正确触发,这就是我想要的。奇怪的是,如果我单击窗口顶部的“菜单”按钮,LostFocus 事件不会在文本框中触发。有没有一种优雅的方法来确保我的菜单正确地允许 LostFocus 触发最后获得焦点的任何控件?
我还想避免更新 BindingExpressions,否则我可能会为 N 个文本框执行此操作,这是不可取的。
我无法想象实现这一点太困难了。我只是不明白这怎么行不通:在大多数其他情况下,LostFocus 总是会触发。
有什么想法吗?谢谢。
This one is a bit tricky to explain.
I have a usercontrol with some textboxes. I also have a menu just above this usercontrol in the same window. Whenever I tab away, the LostFocus fires correctly on the textbox, and this is what I want. Strangely enough, if I click the Menu button on top of my window, the LostFocus event does not fire on the textbox. Is there an elegant way to make sure that my menu properly allows LostFocus to fire on any controls which last had focus?
I also want to avoid having to Update BindingExpressions otherwise I would likely be doing this for N textboxes, which is undesirable.
I can't imagine it is too difficult to achieve this.. I just don't understand how this doesn't work: in most other situations LostFocus always fires.
Any ideas? Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
菜单也是 WPF 还是 Winforms / UnManaged?如果两者之一,则不会触发失去焦点事件。当从菜单执行保存或其他数据功能时,这可能会对 WPF 控件造成严重破坏。为了解决这个问题,我不得不采取多种方法来解决这个问题。最简单的方法是在用户控件本身上实现鼠标离开事件,并在代码中手动执行您需要的任何操作。
Is the menu WPF as well or Winforms / UnManaged? If either of the two then the lost focus event does not fire. This can play havoc with WPF controls as many time a save or other data function is being performed from the menu. To counter this I have had to implement multiple ways to combat this. The easiest way was to implement a mouse leave event on the user control itself and perform any actions you require manually in code.