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 */ }
Microsoft.UI.Xaml.Input.FocusManager.addEventListener("gettingfocus", onGettingFocus);
Microsoft.UI.Xaml.Input.FocusManager.removeEventListener("gettingfocus", onGettingFocus);
- or -
Microsoft.UI.Xaml.Input.FocusManager.ongettingfocus = onGettingFocus;
Public Shared Custom Event GettingFocus As EventHandler(Of GettingFocusEventArgs) 

事件类型

注解

建议尽可能使用 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 也会 (引发

适用于

另请参阅