Skip to main content

IFocusManager Interface

Definition

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

Manages focus for the application.

public interface IFocusManager

Methods

NameDescription
FindFirstFocusableElementRetrieves the first element that can receive focus.
FindLastFocusableElementRetrieves 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 Method

Retrieves the first element that can receive focus.

public Avalonia.Input.IInputElement FindFirstFocusableElement()

Returns

Avalonia.Input.IInputElement

The first focusable element.

FindLastFocusableElement Method

Retrieves the last element that can receive focus.

public Avalonia.Input.IInputElement FindLastFocusableElement()

Returns

Avalonia.Input.IInputElement

The last focusable element.

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 return true, it is not guaranteed that the focus has been moved to element. The focus might have been 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.