用户是否使用键盘或鼠标离开 WPF TextBox?

发布于 2024-11-15 03:46:37 字数 323 浏览 11 评论 0原文

我有一个用于 TextBox 的 PreviewLostKeyboardFocus 事件的处理程序。当我使用键盘(Tab 键)或鼠标(通过单击表单上的另一个文本框)离开文本框时,它会触发。

该处理程序采用一个 KeyboardFocusChangedEventArgs,它有一个名为 KeyboardDevice 的属性,在这两种情况下该属性都不为 null(我希望在这里找到 null使用鼠标时)。

问题:如何判断用户是使用键盘还是鼠标离开 WPF 文本框?

I have a handler for the TextBox's PreviewLostKeyboardFocus event. It fires when I leave the TextBox using the keyboard (Tab key) or the mouse (by clicking on another TextBox on the form).

The handler takes a KeyboardFocusChangedEventArgs, which has a property named KeyboardDevice, which isn't null in either scenario (I was hoping to find null here when using the mouse).

Question: How can I tell whether a user used the keyboard or the mouse to leave a WPF TextBox?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

没︽人懂的悲伤 2024-11-22 03:46:37

e.KeyboardDevice.GetKeyStates(Key.Tab)(其中 e 的类型为 KeyboardFocusChangedEventArgs)报告:

  • None(当使用鼠标更改焦点时)
  • Down,切换(当使用 TAB 离开文本框时)

这对您有用吗?

The e.KeyboardDevice.GetKeyStates(Key.Tab) (where e is of type KeyboardFocusChangedEventArgs) reports:

  • None (when mouse was used to change focus)
  • Down, Toggled (when TAB was use to leave the TextBox)

Would that work for you?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文