Skip to main content

FocusManager Class

Definition​

Namespace:Avalonia.Input
Assembly:Avalonia.Base
Package:Avalonia

Manages focus for the application.

public class FocusManager

Inheritance: object -> FocusManager

Implements:IFocusManager

Methods​

NameDescription
FindFirstFocusableElement (2 overloads)Retrieves the first element that can receive focus.
FindLastFocusableElement (2 overloads)Retrieves the last element that can receive focus.
FindNextElementRetrieves the element that should receive focus based on the specified navigation direction.
FocusFocuses a control.
GetFocusedElementGets the currently focused Avalonia.Input.IInputElement.
TryMoveFocusAttempts to change focus from the element with focus to the next focusable element in the specified direction.

FindFirstFocusableElement overloads​

FindFirstFocusableElement Method​

Retrieves the first element that can receive focus.

public Avalonia.Input.IInputElement FindFirstFocusableElement()
Returns​

Avalonia.Input.IInputElement

The first focusable element.

FindFirstFocusableElement Method​

Retrieves the first element that can receive focus based on the specified scope.

public Avalonia.Input.IInputElement FindFirstFocusableElement(Avalonia.Input.IInputElement searchScope)
Parameters​

searchScope Avalonia.Input.IInputElement

The root element from which to search.

Returns​

Avalonia.Input.IInputElement

The first focusable element.

FindLastFocusableElement overloads​

FindLastFocusableElement Method​

Retrieves the last element that can receive focus.

public Avalonia.Input.IInputElement FindLastFocusableElement()
Returns​

Avalonia.Input.IInputElement

The last focusable element.

FindLastFocusableElement Method​

Retrieves the last element that can receive focus based on the specified scope.

public Avalonia.Input.IInputElement FindLastFocusableElement(Avalonia.Input.IInputElement searchScope)
Parameters​

searchScope Avalonia.Input.IInputElement

The root element from which to search.

Returns​

Avalonia.Input.IInputElement

The last focusable object.

FindNextElement Method​

Retrieves the element that should receive focus based on the specified navigation direction.

public Avalonia.Input.IInputElement FindNextElement(Avalonia.Input.NavigationDirection direction, Avalonia.Input.FindNextElementOptions options)

Parameters​

direction Avalonia.Input.NavigationDirection

The direction that focus moves from element to element. Must be one of Avalonia.Input.NavigationDirection.Next, Avalonia.Input.NavigationDirection.Previous, Avalonia.Input.NavigationDirection.Left, Avalonia.Input.NavigationDirection.Right, Avalonia.Input.NavigationDirection.Up and Avalonia.Input.NavigationDirection.Down.

options Avalonia.Input.FindNextElementOptions

The options to help identify the next element to receive focus.

Returns​

Avalonia.Input.IInputElement

The next element to receive focus, if any.

Focus Method​

Focuses a control.

public bool Focus(Avalonia.Input.IInputElement element, Avalonia.Input.NavigationMethod method, Avalonia.Input.KeyModifiers keyModifiers)

Parameters​

element Avalonia.Input.IInputElement

The control to focus.

method Avalonia.Input.NavigationMethod

The method by which focus was changed.

keyModifiers Avalonia.Input.KeyModifiers

Any key modifiers active at the time of focus.

Returns​

bool

true if the focus moved to a control; otherwise, false.

Remarks​

If element is null, this method tries to clear the focus. However, it is not advised. For a better user experience, focus should be moved to another element when possible.

When this method returns true, the focus has been moved to element. When this method returns false, the focus may have been canceled or redirected to another element.

GetFocusedElement Method​

Gets the currently focused Avalonia.Input.IInputElement.

public Avalonia.Input.IInputElement GetFocusedElement()

Returns​

Avalonia.Input.IInputElement

TryMoveFocus Method​

Attempts to change focus from the element with focus to the next focusable element in the specified direction.

public bool TryMoveFocus(Avalonia.Input.NavigationDirection direction, Avalonia.Input.FindNextElementOptions options)

Parameters​

direction Avalonia.Input.NavigationDirection

The direction that focus moves from element to element. Must be one of Avalonia.Input.NavigationDirection.Next, Avalonia.Input.NavigationDirection.Previous, Avalonia.Input.NavigationDirection.Left, Avalonia.Input.NavigationDirection.Right, Avalonia.Input.NavigationDirection.Up and Avalonia.Input.NavigationDirection.Down.

options Avalonia.Input.FindNextElementOptions

The options to help identify the next element to receive focus.

Returns​

bool

true if focus moved; otherwise, false.