【msdn wpf forum翻译】获取当前窗口焦点所在的元素

原文地址: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/6bd7a03a-f0b4-42df-a7f2-5182cf003cb0

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).

原文地址:https://www.cnblogs.com/caoyang/p/1535553.html