如何辨别焦点改变的手段 [英] How to discern the means of focus change

查看:62
本文介绍了如何辨别焦点改变的手段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.这是WPF的问题,我希望这是提出问题的正确位置.

Hi all. This is a WPF question, and I hope this is the right place to ask it.

当UIElement收到键盘焦点时,它将生成一个我可以订阅的GotKeyboardFocus事件.我的问题是,什么是了解焦点如何到达的最佳方法是什么.具体来说,我想知道焦点是否通过键盘操作到达(例如 (例如Tab键,访问键或加速键)或其他某种方式(例如点击或单击),以便我可以区分出于UI目的的键盘用户和鼠标用户.

查看  KeyboardFocusChangedEventArgs(GotKeyboardFocus事件的事件参数类)的文档,我得到的印象是我可以使用Device属性返回的对象的类型.但是,焦点是否通过制表符更改了 按键或鼠标单击时,此属性始终返回一个KeyboardDevice对象,而不是MouseDevice对象.检查键盘状态并不理想,因为可以使用多种方式移动键盘来移动焦点.

When a UIElement receives the keyboard focus, it generates a GotKeyboardFocus event I can subscribe to. My question is, what is the best way to know *how* focus got there. Specifically, I'd like to know if the focus arrived by a keyboard operation (such as a tab key, access key, or accelerator key) or by some other means (such as a tap or click) so I can discern between a keyboard user and a mouse user for UI purposes.

Looking at the documentation for  KeyboardFocusChangedEventArgs (the event argument class for the GotKeyboardFocus event), I got the impression I could use the type of the object returned by the Device property. However, whether the focus changed via tab key or mouse click, this property always returns a KeyboardDevice object--not a MouseDevice object. Examining the keyboard state is not ideal because there are so many ways a keyboard can be used to move focus.

推荐答案

您好

Hi jfjerstad,

由于您的问题与有关 WPF论坛

Since your issue is related to WPF forum

常规Windows桌面开发问题"论坛讨论并提出有关为Windows开发应用程序的问题.

The General Windows Desktop Development Issues forum discuss and ask question about developing applications for Windows.

但是MSDN已经为WPF指定了论坛.因此,为了更好地支持您.我将把案件移到WPF论坛.

But MSDN has specified forum for WPF. So for the better support you. I will move the case to WPF forum.

最好的问候,

Hart


这篇关于如何辨别焦点改变的手段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆