难道用户在使用键盘或鼠标离开WPF文本框? [英] Did user use keyboard or mouse to leave WPF TextBox?
问题描述
我有文本框的 PreviewLostKeyboardFocus
事件的处理程序。当我使用键盘(Tab键)或鼠标(点击窗体上的另一个文本框)离开文本框它闪光。
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).
处理程序需要 KeyboardFocusChangedEventArgs
,其中有 KeyboardDevice
,名为属性,它不是空在两种情况下(我希望能找到<$ C $ 。C>空这里使用鼠标时)
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).
问:如何判断一个用户是否使用键盘或鼠标离开WPF的TextBox?
Question: How can I tell whether a user used the keyboard or the mouse to leave a WPF TextBox?
推荐答案
在 e.KeyboardDevice.GetKeyStates(Key.Tab)(其中e是类型KeyboardFocusChangedEventArgs的)报告:
The e.KeyboardDevice.GetKeyStates(Key.Tab) (where e is of type KeyboardFocusChangedEventArgs) reports:
- 无(当鼠标被用来改变焦点)
- 下,切换(当TAB是利用离开文本框)
- None (when mouse was used to change focus)
- Down, Toggled (when TAB was use to leave the TextBox)
会为你工作?
这篇关于难道用户在使用键盘或鼠标离开WPF文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!