Keyboard.FocusedElement 属性

定义

获取具有键盘焦点的元素。

public:
 static property System::Windows::IInputElement ^ FocusedElement { System::Windows::IInputElement ^ get(); };
public static System.Windows.IInputElement FocusedElement { get; }
static member FocusedElement : System.Windows.IInputElement
Public Shared ReadOnly Property FocusedElement As IInputElement

属性值

焦点元素。

示例

以下示例获取具有键盘焦点的元素,并将其强制转换为 Control。 如果具有键盘焦点的元素是一个 Control,则元素的背景将更改。

// Gets the element with keyboard focus.
UIElement elementWithFocus = Keyboard.FocusedElement as UIElement;
' Gets the element with keyboard focus.
Dim elementWithFocus As UIElement = TryCast(Keyboard.FocusedElement, UIElement)

注解

键盘焦点是指接收键盘输入的对象。 具有键盘焦点的元素已 IsKeyboardFocused 设置为 true。 整个桌面上只能有一个具有键盘焦点的元素。 逻辑焦点是指具有焦点的焦点范围内的对象。 有关焦点、键盘焦点和逻辑焦点的详细信息,请参阅 输入概述焦点概述

具有键盘焦点的元素也具有元素所属的焦点范围的逻辑焦点。 具有逻辑焦点的元素可能或可能没有键盘焦点。

适用于