KeyboardNavigation.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Copyright (c) The Perspex Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. namespace Perspex.Input
  4. {
  5. /// <summary>
  6. /// Defines attached properties that control keyboard navigation behaviour for a container.
  7. /// </summary>
  8. public static class KeyboardNavigation
  9. {
  10. /// <summary>
  11. /// Defines the DirectionalNavigation attached property.
  12. /// </summary>
  13. /// <remarks>
  14. /// The DirectionalNavigation attached property defines how pressing arrow keys causes
  15. /// focus to be navigated between the children of the container.
  16. /// </remarks>
  17. public static readonly AttachedProperty<KeyboardNavigationMode> DirectionalNavigationProperty =
  18. PerspexProperty.RegisterAttached<InputElement, KeyboardNavigationMode>(
  19. "DirectionalNavigation",
  20. typeof(KeyboardNavigation),
  21. KeyboardNavigationMode.None);
  22. /// <summary>
  23. /// Defines the TabNavigation attached property.
  24. /// </summary>
  25. /// <remarks>
  26. /// The TabNavigation attached property defines how pressing the Tab key causes focus to
  27. /// be navigated between the children of the container.
  28. /// </remarks>
  29. public static readonly AttachedProperty<KeyboardNavigationMode> TabNavigationProperty =
  30. PerspexProperty.RegisterAttached<InputElement, KeyboardNavigationMode>(
  31. "TabNavigation",
  32. typeof(KeyboardNavigation));
  33. /// <summary>
  34. /// Defines the TabOnceActiveElement attached property.
  35. /// </summary>
  36. /// <remarks>
  37. /// When focus enters a container which has its <see cref="TabNavigationProperty"/>
  38. /// attached property set to <see cref="KeyboardNavigationMode.Once"/>, this property
  39. /// defines to which child the focus should move.
  40. /// </remarks>
  41. public static readonly AttachedProperty<IInputElement> TabOnceActiveElementProperty =
  42. PerspexProperty.RegisterAttached<InputElement, IInputElement>(
  43. "TabOnceActiveElement",
  44. typeof(KeyboardNavigation));
  45. /// <summary>
  46. /// Gets the <see cref="DirectionalNavigationProperty"/> for a container.
  47. /// </summary>
  48. /// <param name="element">The container.</param>
  49. /// <returns>The <see cref="KeyboardNavigationMode"/> for the container.</returns>
  50. public static KeyboardNavigationMode GetDirectionalNavigation(InputElement element)
  51. {
  52. return element.GetValue(DirectionalNavigationProperty);
  53. }
  54. /// <summary>
  55. /// Sets the <see cref="DirectionalNavigationProperty"/> for a container.
  56. /// </summary>
  57. /// <param name="element">The container.</param>
  58. /// <param name="value">The <see cref="KeyboardNavigationMode"/> for the container.</param>
  59. public static void SetDirectionalNavigation(InputElement element, KeyboardNavigationMode value)
  60. {
  61. element.SetValue(DirectionalNavigationProperty, value);
  62. }
  63. /// <summary>
  64. /// Gets the <see cref="TabNavigationProperty"/> for a container.
  65. /// </summary>
  66. /// <param name="element">The container.</param>
  67. /// <returns>The <see cref="KeyboardNavigationMode"/> for the container.</returns>
  68. public static KeyboardNavigationMode GetTabNavigation(InputElement element)
  69. {
  70. return element.GetValue(TabNavigationProperty);
  71. }
  72. /// <summary>
  73. /// Sets the <see cref="TabNavigationProperty"/> for a container.
  74. /// </summary>
  75. /// <param name="element">The container.</param>
  76. /// <param name="value">The <see cref="KeyboardNavigationMode"/> for the container.</param>
  77. public static void SetTabNavigation(InputElement element, KeyboardNavigationMode value)
  78. {
  79. element.SetValue(TabNavigationProperty, value);
  80. }
  81. /// <summary>
  82. /// Gets the <see cref="TabOnceActiveElementProperty"/> for a container.
  83. /// </summary>
  84. /// <param name="element">The container.</param>
  85. /// <returns>The active element for the container.</returns>
  86. public static IInputElement GetTabOnceActiveElement(InputElement element)
  87. {
  88. return element.GetValue(TabOnceActiveElementProperty);
  89. }
  90. /// <summary>
  91. /// Sets the <see cref="TabOnceActiveElementProperty"/> for a container.
  92. /// </summary>
  93. /// <param name="element">The container.</param>
  94. /// <param name="value">The active element for the container.</param>
  95. public static void SetTabOnceActiveElement(InputElement element, IInputElement value)
  96. {
  97. element.SetValue(TabOnceActiveElementProperty, value);
  98. }
  99. }
  100. }