Delen via


FocusManager.GettingFocus Event

Definition

Occurs before an element actually receives focus. This event is raised synchronously to ensure focus isn't moved while the event is bubbling.

// 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) 

Event Type

Windows requirements

Device family
Windows 10, version 1809 (introduced in 10.0.17763.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v7.0)

Remarks

We recommend using the UIElement focus routed events instead of FocusManager events whenever possible.

FocusNavigationDirection.Previous and FocusNavigationDirection.Next cannot be used with FindNextElementOptions. Only FocusNavigationDirection.Up, FocusNavigationDirection.Down, FocusNavigationDirection.Left, or FocusNavigationDirection.Right are valid.

UIElement focus events bubble up to the FocusManager in the following order:

  1. UIElement.LosingFocus/FocusManager.LosingFocus
  2. UIElement.GettingFocus/FocusManager.GettingFocus
  3. UIElement.LostFocus routed event is raised by the element that lost focus and the event bubbles up
  4. FocusManager.LostFocus is raised (even if the routed event is marked handled)
  5. UIElement.GotFocus routed event is raised by the element that received focus and the event bubbles up
  6. FocusManager.GotFocus is raised (even if the routed event is marked handled)

Applies to

See also