Focus
Focus refers to the InputElement which is expected to receive keyboard input and are typically
distinguished with a visual indicator. The most familiar example is a TextBox with a blinking cursor inside, but
non-textual controls like Button and Slider also participate in focus.
IsFocused and Focusable
IsFocused is a get-only property that keeps track of the InputElement's focus state.
The Focusable property enables or disables the ability to focus an InputElement. Elements which cannot be focused
can still be interacted with via pointer, so some care should be taken that a functional keyboard equivalent (such as
hotkeys) is available when possible.
Explicit Focusing
To explicitly assign focus to any InputElement, call its .Focus() method from code. Optionally, you may specify the
NavigationMethod and KeyModifiers to simulate as if the focus were triggered by a specific focus navigation flow. Explicit
focusing is often used to focus a specific InputElement in a data entry form upon loading or to programmatically move
to the next InputControl once the current input has been satisfied.
| NavigationMethod | Trigger Description |
|---|---|
| Tab | Tab key press |
| Pointer | Pointer interaction |
| Directional | 2D Directional (XYFocus) |
| Unspecified | Default |
Focus Events
InputElements expose GotFocus and LostFocus events. The GotFocusEventArgs contains the NavigationMethod and
KeyModifiers used to trigger the focus navigation.