FocusManager.GettingFocus 事件

定义

在元素实际接收焦点之前发生。 此事件是同步引发的,以确保在事件冒泡时不会移动焦点。

// Register
static event_token GettingFocus(EventHandler<GettingFocusEventArgs> const& handler) const;

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

// Revoke with event_revoker
static FocusManager::GettingFocus_revoker GettingFocus(auto_revoke_t, EventHandler<GettingFocusEventArgs> const& handler) const;
public static event System.EventHandler<GettingFocusEventArgs> GettingFocus;
function onGettingFocus(eventArgs) { /* Your code */ }
Windows.UI.Xaml.Input.FocusManager.addEventListener("gettingfocus", onGettingFocus);
Windows.UI.Xaml.Input.FocusManager.removeEventListener("gettingfocus", onGettingFocus);
- or -
Windows.UI.Xaml.Input.FocusManager.ongettingfocus = onGettingFocus;
Public Shared Custom Event GettingFocus As EventHandler(Of GettingFocusEventArgs) 

事件类型

Windows 要求

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

注解

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

FocusNavigationDirection.PreviousFocusNavigationDirection.Next 不能与 FindNextElementOptions 一起使用。 只有 FocusNavigationDirection.UpFocusNavigationDirection.DownFocusNavigationDirection.LeftFocusNavigationDirection.Right 有效。

UIElement 焦点事件按以下顺序向上气泡到 FocusManager:

  1. UIElement.LosingFocus/FocusManager.LosingFocus
  2. UIElement.GettingFocus/FocusManager.GettingFocus
  3. UIElement.LostFocus 路由事件由失去焦点的元素引发,该事件向上气泡
  4. focusManager.LostFocus (引发,即使路由事件标记为已处理)
  5. UIElement.GotFocus 路由事件由接收焦点的元素引发,事件浮出
  6. focusManager.GotFocus 将引发 (,即使路由事件标记为已处理)

适用于

另请参阅