FocusManager.LosingFocus 事件

定义

在焦点从具有焦点的当前元素移动到目标元素之前发生。 此事件是同步引发的,以确保在事件冒泡时不会移动焦点。

// Register
static event_token LosingFocus(EventHandler<LosingFocusEventArgs> const& handler) const;

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

// Revoke with event_revoker
static FocusManager::LosingFocus_revoker LosingFocus(auto_revoke_t, EventHandler<LosingFocusEventArgs> const& handler) const;
public static event System.EventHandler<LosingFocusEventArgs> LosingFocus;
function onLosingFocus(eventArgs) { /* Your code */ }
Windows.UI.Xaml.Input.FocusManager.addEventListener("losingfocus", onLosingFocus);
Windows.UI.Xaml.Input.FocusManager.removeEventListener("losingfocus", onLosingFocus);
- or -
Windows.UI.Xaml.Input.FocusManager.onlosingfocus = onLosingFocus;
Public Shared Custom Event LosingFocus As EventHandler(Of LosingFocusEventArgs) 
<uiElement LosingFocus="eventhandler"/>

事件类型

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 也会 (引发

适用于

另请参阅