FocusManager FocusManager FocusManager Class

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

Syntax

Declaration

public sealed class FocusManagerpublic sealed class FocusManagerPublic NotInheritable Class FocusManager

Remarks

Examples

Use TryMoveFocus(FocusNavigationDirection, FindNextElementOptions) 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 summary

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

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

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

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

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

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

Gets the element in the UI that has focus.

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

Prerelease. 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.

Methods

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

    Prerelease. 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 DependencyObjectpublic static DependencyObject FindFirstFocusableElement(DependencyObject searchScope)

    Parameters

    Returns

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

    Prerelease. 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 DependencyObjectpublic static DependencyObject FindLastFocusableElement(DependencyObject searchScope)

    Parameters

    Returns

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

    Prerelease. 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 DependencyObjectpublic static DependencyObject FindNextElement(FocusNavigationDirection focusNavigationDirection)

    Parameters

    Returns

    Remarks

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

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

    Prerelease. 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 DependencyObjectpublic static DependencyObject FindNextElement(FocusNavigationDirection focusNavigationDirection, FindNextElementOptions focusNavigationOptions)

    Parameters

    Returns

    Remarks

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

  • FindNextFocusableElement(FocusNavigationDirection)
    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 UIElementpublic static UIElement FindNextFocusableElement(FocusNavigationDirection focusNavigationDirection)

    Parameters

    Returns

  • 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.

    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 UIElementpublic static UIElement FindNextFocusableElement(FocusNavigationDirection focusNavigationDirection, Rect hintRect)

    Parameters

    • focusNavigationDirection

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

    • hintRect

      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

  • GetFocusedElement()
    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 objectpublic static object GetFocusedElement()

    Returns

    • object
      object
      object

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

  • 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.

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

    Parameters

    Returns

    • bool
      bool
      bool

      true if focus moved; otherwise, false.

    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 is specified, focus moves to the last element.

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

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

    Prerelease. 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 boolpublic static bool TryMoveFocus(FocusNavigationDirection focusNavigationDirection, FindNextElementOptions focusNavigationOptions)

    Parameters

    Returns

    • bool
      bool
      bool

      true if focus moved; otherwise, false.

    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 is specified, focus moves to the last element.

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

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.ThreadingAttribute
Windows.Foundation.Metadata.WebHostHiddenAttribute

Details

Assembly

Windows.UI.Xaml.Input.dll