FocusManager.GetFocusedElement(DependencyObject) 方法

定义

获取在指定焦点范围内具有逻辑焦点的元素。Gets the element with logical focus within the specified focus scope.

public:
 static System::Windows::IInputElement ^ GetFocusedElement(System::Windows::DependencyObject ^ element);
public static System.Windows.IInputElement GetFocusedElement (System.Windows.DependencyObject element);
static member GetFocusedElement : System.Windows.DependencyObject -> System.Windows.IInputElement
Public Shared Function GetFocusedElement (element As DependencyObject) As IInputElement

参数

element
DependencyObject

作为焦点范围的元素。An element that is a focus scope.

返回

IInputElement

在指定焦点范围内具有逻辑焦点的元素。The element in the specified focus scope with logical focus.

例外

elementnullelement is null.

示例

下面的示例使用来设置具有逻辑焦点的元素 SetFocusedElement ,并使用来获取具有逻辑焦点的元素 GetFocusedElementThe following example sets the element with logical focus by using the SetFocusedElement and it gets the element with logical focus by using the GetFocusedElement.

// Sets the focused element in focusScope1
// focusScope1 is a StackPanel.
FocusManager.SetFocusedElement(focusScope1, button2);

// Gets the focused element for focusScope 1
IInputElement focusedElement = FocusManager.GetFocusedElement(focusScope1);
' Sets the focused element in focusScope1
' focusScope1 is a StackPanel.
FocusManager.SetFocusedElement(focusScope1, button2)

' Gets the focused element for focusScope 1
Dim focusedElement As IInputElement = FocusManager.GetFocusedElement(focusScope1)

注解

FocusedElement是对特定焦点范围具有逻辑焦点的元素。The FocusedElement is the element that has logical focus for a specific focus scope. 作为焦点范围的元素已 IsFocusScope 设置为 trueAn element that is a focus scope has IsFocusScope set to true. 此对象不一定具有键盘焦点。This object may or may not have keyboard focus. 键盘焦点指的是接收键盘输入的元素。Keyboard focus refers to the element that receives keyboard input. 有关焦点、键盘焦点和逻辑焦点的详细信息,请参阅 输入概述For more information on focus, keyboard focus, and logical focus, see the Input Overview.

如果不是 element 焦点范围,则此方法将返回 nullIf element is not a focus scope, this method will return null.

使用 SetFocusedElement ,指定在指定焦点范围内具有逻辑焦点的元素。Use SetFocusedElement, to specify the element with logical focus within a specified focus scope.

适用于