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。 整個桌面上只能有一個具有鍵盤焦點的專案。 邏輯焦點是指焦點範圍內具有焦點的物件。 如需焦點、鍵盤焦點和邏輯焦點的詳細資訊,請參閱 輸入概觀焦點概觀

具有鍵盤焦點的專案也有元素所屬焦點範圍的邏輯焦點。 具有邏輯焦點的專案可能或可能沒有鍵盤焦點。

適用於