Focus​Manager Focus​Manager Focus​Manager Class

Definition

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

public sealed class FocusManager : IFocusManagerpublic sealed class FocusManager : IFocusManagerPublic 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)

Remarks

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)

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

public static DependencyObject FindFirstFocusableElement(DependencyObject searchScope)public static DependencyObject FindFirstFocusableElement(DependencyObject searchScope)Public Static Function FindFirstFocusableElement(searchScope As DependencyObject) As DependencyObject
Parameters
searchScope
DependencyObject DependencyObject DependencyObject

The root object from which to search. If null, the search scope is the current window.

Returns

The first focusable object.

Attributes
Additional features and requirements
Device family
Windows 10 Creators Update (introduced v10.0.15063.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v4)

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

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

public static DependencyObject FindLastFocusableElement(DependencyObject searchScope)public static DependencyObject FindLastFocusableElement(DependencyObject searchScope)Public Static Function FindLastFocusableElement(searchScope As DependencyObject) As DependencyObject
Parameters
searchScope
DependencyObject DependencyObject DependencyObject

The root object from which to search. If null, the search scope is the current window.

Returns
Attributes
Additional features and requirements
Device family
Windows 10 Creators Update (introduced v10.0.15063.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v4)

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

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

public static DependencyObject FindNextElement(FocusNavigationDirection focusNavigationDirection)public static DependencyObject FindNextElement(FocusNavigationDirection focusNavigationDirection)Public Static Function FindNextElement(focusNavigationDirection As FocusNavigationDirection) As DependencyObject
Parameters
focusNavigationDirection
FocusNavigationDirection FocusNavigationDirection FocusNavigationDirection

The direction that focus moves from element to element within the app UI.

Returns

The next object to receive focus.

Attributes
Additional features and requirements
Device family
Windows 10 Creators Update (introduced v10.0.15063.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v4)

Remarks

We recommend using this method instead of FindNextFocusableElement(FocusNavigationDirection).

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

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

public static DependencyObject FindNextElement(FocusNavigationDirection focusNavigationDirection, FindNextElementOptions focusNavigationOptions)public static DependencyObject FindNextElement(FocusNavigationDirection focusNavigationDirection, FindNextElementOptions focusNavigationOptions)Public Static Function FindNextElement(focusNavigationDirection As FocusNavigationDirection, focusNavigationOptions As FindNextElementOptions) As DependencyObject
Parameters
focusNavigationDirection
FocusNavigationDirection FocusNavigationDirection FocusNavigationDirection

The direction that focus moves from element to element within the app UI.

focusNavigationOptions
FindNextElementOptions FindNextElementOptions FindNextElementOptions

The options to help identify the next element to receive focus with keyboard/controller/remote navigation.

Returns

The next object to receive focus.

Attributes
Additional features and requirements
Device family
Windows 10 Creators Update (introduced v10.0.15063.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v4)

Remarks

We recommend using this method instead of FindNextFocusableElement(FocusNavigationDirection, Rect).

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

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

public static UIElement FindNextFocusableElement(FocusNavigationDirection focusNavigationDirection)public static UIElement FindNextFocusableElement(FocusNavigationDirection focusNavigationDirection)Public Static Function FindNextFocusableElement(focusNavigationDirection As FocusNavigationDirection) As UIElement
Parameters
focusNavigationDirection
FocusNavigationDirection FocusNavigationDirection FocusNavigationDirection

The direction that focus moves from element to element within the app UI.

Returns

null if focus cannot be set in the specified direction.

Attributes

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.

public static UIElement FindNextFocusableElement(FocusNavigationDirection focusNavigationDirection, Rect hintRect)public static UIElement FindNextFocusableElement(FocusNavigationDirection focusNavigationDirection, Rect hintRect)Public Static Function FindNextFocusableElement(focusNavigationDirection As FocusNavigationDirection, hintRect As Rect) As UIElement
Parameters
focusNavigationDirection
FocusNavigationDirection FocusNavigationDirection FocusNavigationDirection

The direction that focus moves from element to element within the app UI.

hintRect
Rect Rect Rect

A bounding rectangle used to influence which element is most likely to be considered the next to receive focus. Examples where this can be useful include:

  • When no element currently has focus, specifying a small rectangle at a screen location of (-1, -1) starts focus from the upper left corner of the display.
  • In a program guide where you want to ensure programs at the current time receive focus. (The focus algorithm might favor shows at a later time based on a number of factors.)
Returns

null if focus cannot be set in the specified direction.

Attributes

GetFocusedElement() GetFocusedElement() GetFocusedElement()

Gets the element in the UI that has focus.

public static object GetFocusedElement()public static object GetFocusedElement()Public Static Function GetFocusedElement() As object
Returns
object object object

The object that has focus. Typically, this is a Control class.

Attributes

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

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

public static bool TryMoveFocus(FocusNavigationDirection focusNavigationDirection)public static bool TryMoveFocus(FocusNavigationDirection focusNavigationDirection)Public Static Function TryMoveFocus(focusNavigationDirection As FocusNavigationDirection) As bool
Parameters
focusNavigationDirection
FocusNavigationDirection FocusNavigationDirection FocusNavigationDirection

The direction to traverse (in tab order).

Returns
bool bool bool

true if focus moved; otherwise, false.

Attributes

Remarks

The tab order is the order in which a user moves from one control to another by pressing the Tab key (forward) or Shift+Tab (backward).

This method uses tab order sequence and behavior to traverse all focusable elements in the UI.

If the focus is on the first element in the tab order and FocusNavigationDirection.Previous is specified, focus moves to the last element.

If the focus is on the last element in the tab order and FocusNavigationDirection.Next is specified, focus moves to the first element.

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.

public static bool TryMoveFocus(FocusNavigationDirection focusNavigationDirection, FindNextElementOptions focusNavigationOptions)public static bool TryMoveFocus(FocusNavigationDirection focusNavigationDirection, FindNextElementOptions focusNavigationOptions)Public Static Function TryMoveFocus(focusNavigationDirection As FocusNavigationDirection, focusNavigationOptions As FindNextElementOptions) As bool
Parameters
focusNavigationDirection
FocusNavigationDirection FocusNavigationDirection FocusNavigationDirection

The direction to traverse (in tab order).

focusNavigationOptions
FindNextElementOptions FindNextElementOptions FindNextElementOptions

The options to help identify the next element to receive focus with keyboard/controller/remote navigation.

Returns
bool bool bool

true if focus moved; otherwise, false.

Attributes
Additional features and requirements
Device family
Windows 10 Creators Update (introduced v10.0.15063.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v4)

Remarks

The tab order is the order in which a user moves from one control to another by pressing the Tab key (forward) or Shift+Tab (backward).

This method uses tab order sequence and behavior to traverse all focusable elements in the UI.

If the focus is on the first element in the tab order and FocusNavigationDirection.Previous is specified, focus moves to the last element.

If the focus is on the last element in the tab order and FocusNavigationDirection.Next is specified, focus moves to the first element.