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

本文介绍了如何在WPF应用程序中使用FocusManager.GetFocusedElement方法来确定当前窗口中具有逻辑焦点的元素。文中还解释了逻辑焦点与键盘焦点的区别,并提供了检查元素是否具有键盘焦点的方法。
原文: 【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).

posted on 2018-07-11 01:16 NET未来之路 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/lonelyxmas/p/9292361.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值