Share via


FocusManager.GotFocus Event

Definition

Occurs when an element within a container element (a focus scope) receives focus. This event is raised asynchronously, so focus might move before bubbling is complete.

// 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 */ }
Microsoft.UI.Xaml.Input.FocusManager.addEventListener("gotfocus", onGotFocus);
Microsoft.UI.Xaml.Input.FocusManager.removeEventListener("gotfocus", onGotFocus);
- or -
Microsoft.UI.Xaml.Input.FocusManager.ongotfocus = onGotFocus;
Public Shared Custom Event GotFocus As EventHandler(Of FocusManagerGotFocusEventArgs) 

Event Type

Remarks

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

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