FocusManager.GotFocus 事件

定义

当容器元素中的元素 (焦点范围) 接收焦点时发生。 此事件以异步方式引发,因此焦点可能会在冒泡完成之前移动。

// Register
static event_token GotFocus(EventHandler<FocusManagerGotFocusEventArgs> const& handler) const;

// Revoke with event_token
static void GotFocus(event_token const* cookie) const;

// Revoke with event_revoker
static FocusManager::GotFocus_revoker GotFocus(auto_revoke_t, EventHandler<FocusManagerGotFocusEventArgs> const& handler) const;
public static event System.EventHandler<FocusManagerGotFocusEventArgs> GotFocus;
function onGotFocus(eventArgs) { /* Your code */ }
Windows.UI.Xaml.Input.FocusManager.addEventListener("gotfocus", onGotFocus);
Windows.UI.Xaml.Input.FocusManager.removeEventListener("gotfocus", onGotFocus);
- or -
Windows.UI.Xaml.Input.FocusManager.ongotfocus = onGotFocus;
Public Shared Custom Event GotFocus As EventHandler(Of FocusManagerGotFocusEventArgs) 

事件类型

Windows 要求

设备系列
Windows 10, version 1809 (在 10.0.17763.0 中引入)
API contract
Windows.Foundation.UniversalApiContract (在 v7.0 中引入)

注解

建议尽可能使用 UIElement 焦点路由事件而不是 FocusManager 事件。

UIElement 焦点事件按以下顺序浮升到 FocusManager:

  1. UIElement.LosingFocus/FocusManager.LosingFocus
  2. UIElement.GettingFocus/FocusManager.GettingFocus
  3. UIElement.LostFocus 路由事件由失去焦点的元素引发,并且事件浮升
  4. 即使路由事件标记为已处理) ,focusManager.LostFocus 也会引发 (
  5. UIElement.GotFocus 路由事件由接收焦点的元素引发,事件浮升
  6. 即使路由事件标记为已处理) ,focusManager.GotFocus 也会 (引发

适用于

另请参阅