博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【msdn wpf forum翻译】获取当前窗口焦点所在的元素
阅读量:7003 次
发布时间:2019-06-27

本文共 1077 字,大约阅读时间需要 3 分钟。

原文:

原文地址:


Bialgous回答:
IInputElement focusedElement = FocusManager.GetFocusedElement(thisWindow);
有两点需要注意:
1. 逻辑焦点 != 键盘焦点
    比如当你点开一个菜单时,菜单具有物理焦点
2. 要想检查得到的这个元素是否有键盘焦点,需检查 IsKeyboardFocused 属性,如果它 == true,则这个元素有键盘焦点

注:逻辑焦点、物理焦点的概念是什么?不很清楚,请大家赐教:)  ....
以下是原文:

Hi, you can always determine which element has
logical
focus in your application through the
FocusManager.GetFocusedElement method -- pass it the window in question and it will return which element has
logical
focus in that window.  Remember that
logical
focus != keyboard
focus at all times -- toolbars and menus track their own
focus so if you are currently interacting with a menu then the menu has physical
focus.  But in general, the following code will tell you which element
WPF thinks has
focus in the window:

IInputElement focusedElement = FocusManager.GetFocusedElement(thisWindow);

To determine whether this element has keyboard focus, we can check the IsKeyboardFocused property - if it's set to true, then that element currently has the keyboard focus (as well as being the logical focus for that focus scope).

转载地址:http://egutl.baihongyu.com/

你可能感兴趣的文章