Lost Focus Event
Some information relates to pre-released product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
// Register event_token LostFocus(RoutedEventHandler const& handler) const; // Revoke with event_token void LostFocus(event_token const* cookie) const; // Revoke with event_revoker UIElement::LostFocus_revoker LostFocus(auto_revoke_t, RoutedEventHandler const& handler) const;
public event RoutedEventHandler LostFocus;
Public Custom Event LostFocus As RoutedEventHandler
Only a single UI element at a time can have focus.
A control can lose focus when another control gets focus, the application view changes, the user switches applications, or the user interacts with the system such that the application is no longer in the foreground.
LostFocus is raised before GotFocus.
Keyboard focus is particularly relevant for keyboard event handling, because only the currently keyboard-focused UIElement can be the source of the KeyUp and KeyDown key events. Applications might call Focus as an initialization action so that the key events in the app as a whole can be used to detect access or accelerator keys. For more info, see Keyboard interactions.
LostFocus is a routed event. For more info on how class-based handling for events works, see Events and routed events overview.
Specific Windows Runtime controls may have class-based handling for the LostFocus event. If so, the control probably has an override for the method OnLostFocus. Typically the event is marked handled by the class handler, and the LostFocus event is not raised for handling by any user code handlers on that control. Controls might handle the event in order to unload a visual state that displayed a focus rectangle in response to OnGotFocus.
A control's focus rectangle is an important visual component that aids accessibility by identifying the current focused element and indicating where the user is within the tab sequence of the application UI. In some cases, the FocusState of the focus action is relevant for whether a visible focus indicator should display.
For more info on tab sequences and accessibility, see Keyboard accessibility.
- AddHandler(RoutedEvent, Object, Boolean)
- Events and routed events overview
- Keyboard interactions
- Focus navigation for keyboard, gamepad, remote control, and accessibility tools
- Programmatic focus navigation