FocusManager class

Applies to Windows and Windows Phone

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

Inheritance

Object
  FocusManager

Syntax


public sealed class FocusManager

Attributes

[MarshalingBehavior(Agile)]
[Threading(Both)]
[Version(0x06020000)]
[WebHostHidden()]

Members

The FocusManager class has these types of members:

Methods

The FocusManager class has these methods. It also inherits methods from the Object class.

MethodDescription
GetFocusedElement Gets the element in the UI that has focus.
TryMoveFocus Attempts to change focus from the element with focus to the next focusable element in the specified direction.

 

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);
   }
}

Requirements

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.UI.Xaml.Input
Windows::UI::Xaml::Input [C++]

Metadata

Windows.winmd

 

 

Show:
© 2014 Microsoft