FocusManager.GetFocusedElement(DependencyObject) 方法

定義

取得指定焦點範圍內擁有邏輯焦點的項目。

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

屬於焦點範圍的元素。

傳回

在具有邏輯焦點之指定焦點範圍內的項目。

例外狀況

elementnull

範例

下列範例會使用 來 SetFocusedElement 設定具有邏輯焦點的專案,並使用 取得具有邏輯焦點 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是具有特定焦點範圍之邏輯焦點的專案。 焦點範圍的項目已 IsFocusScope 設定為 true。 此物件可能或可能沒有鍵盤焦點。 鍵盤焦點是指接收鍵盤輸入的專案。 如需焦點、鍵盤焦點和邏輯焦點的詳細資訊,請參閱 輸入概觀

如果 element 不是焦點範圍,這個方法會傳回 null

使用 SetFocusedElement,即可在指定的焦點範圍內指定具有邏輯焦點的專案。

適用於