FocusManager
FocusManager
FocusManager
FocusManager
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// This API is not available in Javascript.
- Attributes
| 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.
public : static DependencyObject FindFirstFocusableElement(DependencyObject searchScope)public static DependencyObject FindFirstFocusableElement(DependencyObject searchScope)Public Static Function FindFirstFocusableElement(searchScope As DependencyObject) As DependencyObject// This API is not available in Javascript.
The root object from which to search. If null, the search scope is the current window.
The first focusable object.
| Device family |
Windows 10 Creators Update (introduced v10.0.15063.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v4)
|
FindLastFocusableElement(DependencyObject) 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// This API is not available in Javascript.
The root object from which to search. If null, the search scope is the current window.
The last focusable object.
| Device family |
Windows 10 Creators Update (introduced v10.0.15063.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v4)
|
FindNextElement(FocusNavigationDirection) 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// This API is not available in Javascript.
- focusNavigationDirection
- FocusNavigationDirection FocusNavigationDirection FocusNavigationDirection FocusNavigationDirection
The direction that focus moves from element to element within the app UI.
The next object to receive focus.
| 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) 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// This API is not available in Javascript.
- focusNavigationDirection
- FocusNavigationDirection FocusNavigationDirection FocusNavigationDirection FocusNavigationDirection
The direction that focus moves from element to element within the app UI.
- focusNavigationOptions
- FindNextElementOptions FindNextElementOptions FindNextElementOptions FindNextElementOptions
The options to help identify the next element to receive focus with keyboard/controller/remote navigation.
The next object to receive focus.
| 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) 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// This API is not available in Javascript.
- focusNavigationDirection
- FocusNavigationDirection FocusNavigationDirection FocusNavigationDirection FocusNavigationDirection
The direction that focus moves from element to element within the app UI.
- See Also
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 UIElement// This API is not available in Javascript.
- focusNavigationDirection
- FocusNavigationDirection FocusNavigationDirection FocusNavigationDirection FocusNavigationDirection
The direction that focus moves from element to element within the app UI.
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.)
- See Also
GetFocusedElement() GetFocusedElement() GetFocusedElement() GetFocusedElement()
Gets the element in the UI that has focus.
public : static PlatForm::Object GetFocusedElement()public static object GetFocusedElement()Public Static Function GetFocusedElement() As object// This API is not available in Javascript.
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 PlatForm::Boolean TryMoveFocus(FocusNavigationDirection focusNavigationDirection)public static bool TryMoveFocus(FocusNavigationDirection focusNavigationDirection)Public Static Function TryMoveFocus(focusNavigationDirection As FocusNavigationDirection) As bool// This API is not available in Javascript.
- focusNavigationDirection
- FocusNavigationDirection FocusNavigationDirection FocusNavigationDirection FocusNavigationDirection
The direction to traverse (in tab order).
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.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) 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 PlatForm::Boolean 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// This API is not available in Javascript.
- focusNavigationDirection
- FocusNavigationDirection FocusNavigationDirection FocusNavigationDirection FocusNavigationDirection
The direction to traverse (in tab order).
- focusNavigationOptions
- FindNextElementOptions FindNextElementOptions FindNextElementOptions FindNextElementOptions
The options to help identify the next element to receive focus with keyboard/controller/remote navigation.
true if focus moved; otherwise, false.
| 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.