This topic has not yet been rated - Rate this topic

KeyboardNavigation Class

Provides logical and directional navigation between focusable objects.

System.Object
  System.Windows.Input.KeyboardNavigation

Namespace:  System.Windows.Input
Assembly:  PresentationFramework (in PresentationFramework.dll)
public sealed class KeyboardNavigation

The KeyboardNavigation type exposes the following members.

  Name Description
Public attached property AcceptsReturn Gets or sets a value indicating whether the Return character is accepted by a control.
Public attached property ControlTabNavigation Gets or sets the logical control tab navigation behavior for the children of the element that this property is set on.
Public attached property DirectionalNavigation Gets or sets the directional navigation behavior for the children of the element that this property is set on.
Public attached property IsTabStop Gets or sets a value indicating whether the element that this property is set on is a tab stop.
Public attached property TabIndex Gets or sets the tab index for the element that this property is set on.
Public attached property TabNavigation Gets or sets the logical tab navigation behavior for the children of the element that this property is set on.
Top
  Name Description
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method Static member GetAcceptsReturn Gets the value of the AcceptsReturn attached property for the specified element.
Public method Static member GetControlTabNavigation Gets the value of the ControlTabNavigation attached property for the specified element.
Public method Static member GetDirectionalNavigation Gets the value of the DirectionalNavigation attached property for the specified element.
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method Static member GetIsTabStop Gets the value of the IsTabStop attached property for the specified element.
Public method Static member GetTabIndex Gets the value of the TabIndex  attached property for the specified element.
Public method Static member GetTabNavigation Gets the value of the TabNavigation attached property for the specified element.
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method Static member SetAcceptsReturn Sets the value of the AcceptsReturn  attached property for the specified element.
Public method Static member SetControlTabNavigation Sets the value of the ControlTabNavigation attached property for the specified element.
Public method Static member SetDirectionalNavigation Sets the value of the DirectionalNavigation attached property for the specified element.
Public method Static member SetIsTabStop Sets the value of the IsTabStop attached property for the specified element.
Public method Static member SetTabIndex Set the value of the TabIndex attached property for the specified element.
Public method Static member SetTabNavigation Sets the value of the TabNavigation attached property for the specified element.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Top
  Name Description
Public field Static member AcceptsReturnProperty Identifies the AcceptsReturn attached property.
Public field Static member ControlTabNavigationProperty Identifies the ControlTabNavigation attached property.
Public field Static member DirectionalNavigationProperty Identifies the DirectionalNavigation attached property.
Public field Static member IsTabStopProperty Identifies the IsTabStop attached property.
Public field Static member TabIndexProperty Identifies the TabIndex attached property.
Public field Static member TabNavigationProperty Identifies the TabNavigation attached property.
Top

The KeyboardNavigation class is responsible for implementing default keyboard focus navigation when one of the navigation keys is pressed. The navigation keys are: Tab, Shift+Tab, Ctrl+Tab, Ctrl+Shift+Tab, UpArrow, DownArrow, LeftArrow, and RightArrow keys.

An example of logical navigation is using the tab key to move focus.

An example of directional navigation is using the arrow keys to move focus.

The following example creates a Menu with a number of MenuItem objects. The TabNavigation attached property is set to Cycle on the Menu. This means that when focus is changed using the tab key within the Menu, focus will move from each element and when the last element is reached focus will return to the first element.


<Menu KeyboardNavigation.TabNavigation="Cycle">
  <MenuItem Header="Menu Item 1" />
  <MenuItem Header="Menu Item 2" />
  <MenuItem Header="Menu Item 3" />
  <MenuItem Header="Menu Item 4" />
</Menu>



Menu navigationMenu = new Menu();
MenuItem item1 = new MenuItem();
MenuItem item2 = new MenuItem();
MenuItem item3 = new MenuItem();
MenuItem item4 = new MenuItem();

navigationMenu.Items.Add(item1);
navigationMenu.Items.Add(item2);
navigationMenu.Items.Add(item3);
navigationMenu.Items.Add(item4);

KeyboardNavigation.SetTabNavigation(navigationMenu, 
    KeyboardNavigationMode.Cycle);


.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ