FocusManager FocusManager FocusManager FocusManager Class

Definition

A helper class that enables getting and setting the UI element that has focus.

public : sealed class FocusManager : IFocusManager
struct winrt::Windows::UI::Xaml::Input::FocusManager : IFocusManager
public sealed class FocusManager : IFocusManager
Public NotInheritable Class FocusManager Implements IFocusManager
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Examples

Use TryMoveFocus to traverse between UI elements using the arrow keys.

private void Page_KeyUp(object sender, KeyRoutedEventArgs e)
{
   if (e.Key == Windows.System.VirtualKey.Up)
   {
      // Mimic Shift+Tab when user hits up arrow key.
      FocusManager.TryMoveFocus(FocusNavigationDirection.Previous);
   }
   else if (e.Key == Windows.System.VirtualKey.Down)
   {
      // Mimic Tab when user hits down arrow key.
      FocusManager.TryMoveFocus(FocusNavigationDirection.Next);
   }
}

Methods

FindFirstFocusableElement(DependencyObject) FindFirstFocusableElement(DependencyObject) FindFirstFocusableElement(DependencyObject) FindFirstFocusableElement(DependencyObject)

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

FindLastFocusableElement(DependencyObject) FindLastFocusableElement(DependencyObject) FindLastFocusableElement(DependencyObject) FindLastFocusableElement(DependencyObject)

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

FindNextElement(FocusNavigationDirection) FindNextElement(FocusNavigationDirection) FindNextElement(FocusNavigationDirection) FindNextElement(FocusNavigationDirection)

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

FindNextElement(FocusNavigationDirection, FindNextElementOptions) FindNextElement(FocusNavigationDirection, FindNextElementOptions) FindNextElement(FocusNavigationDirection, FindNextElementOptions) FindNextElement(FocusNavigationDirection, FindNextElementOptions)

Retrieves the element that will receive focus based on the specified navigation direction (cannot be used with tab navigation, see remarks).

FindNextFocusableElement(FocusNavigationDirection) FindNextFocusableElement(FocusNavigationDirection) FindNextFocusableElement(FocusNavigationDirection) FindNextFocusableElement(FocusNavigationDirection)

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

FindNextFocusableElement(FocusNavigationDirection, Rect) FindNextFocusableElement(FocusNavigationDirection, Rect) FindNextFocusableElement(FocusNavigationDirection, Rect) FindNextFocusableElement(FocusNavigationDirection, Rect)

Retrieves the element that will receive focus based on the specified navigation direction and hint rectangle.

GetFocusedElement() GetFocusedElement() GetFocusedElement() GetFocusedElement()

Retrieves the element in the UI that has focus.

TryFocusAsync(DependencyObject, FocusState) TryFocusAsync(DependencyObject, FocusState) TryFocusAsync(DependencyObject, FocusState) TryFocusAsync(DependencyObject, FocusState)

Asynchronously attempts to set focus on an element when the application is initialized.

TryMoveFocus(FocusNavigationDirection) TryMoveFocus(FocusNavigationDirection) TryMoveFocus(FocusNavigationDirection) TryMoveFocus(FocusNavigationDirection)

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

TryMoveFocus(FocusNavigationDirection, FindNextElementOptions) TryMoveFocus(FocusNavigationDirection, FindNextElementOptions) TryMoveFocus(FocusNavigationDirection, FindNextElementOptions) TryMoveFocus(FocusNavigationDirection, FindNextElementOptions)

Attempts to change focus from the element with focus to the next focusable element in both the specified direction and using the specified navigation options.

TryMoveFocusAsync(FocusNavigationDirection) TryMoveFocusAsync(FocusNavigationDirection) TryMoveFocusAsync(FocusNavigationDirection) TryMoveFocusAsync(FocusNavigationDirection)

Asynchronously attempts to change focus from the current element with focus to the next focusable element in the specified direction.

TryMoveFocusAsync(FocusNavigationDirection, FindNextElementOptions) TryMoveFocusAsync(FocusNavigationDirection, FindNextElementOptions) TryMoveFocusAsync(FocusNavigationDirection, FindNextElementOptions) TryMoveFocusAsync(FocusNavigationDirection, FindNextElementOptions)

Asynchronously attempts to change focus from the current element with focus to the next focusable element in the specified direction and subject to the specified navigation options.