Browse Source

Added TabIndex property.

And also added `IsTabStop` property to `InputElement`.
pull/5996/head
Steven Kirk 5 years ago
parent
commit
e42bccd79b
  1. 31
      src/Avalonia.Input/InputElement.cs
  2. 32
      src/Avalonia.Input/KeyboardNavigation.cs

31
src/Avalonia.Input/InputElement.cs

@ -71,6 +71,12 @@ namespace Avalonia.Input
public static readonly DirectProperty<InputElement, bool> IsPointerOverProperty =
AvaloniaProperty.RegisterDirect<InputElement, bool>(nameof(IsPointerOver), o => o.IsPointerOver);
/// <summary>
/// Defines the <see cref="IsTabStop"/> property.
/// </summary>
public static readonly StyledProperty<bool> IsTabStopProperty =
KeyboardNavigation.IsTabStopProperty.AddOwner<InputElement>();
/// <summary>
/// Defines the <see cref="GotFocus"/> event.
/// </summary>
@ -99,6 +105,12 @@ namespace Avalonia.Input
"KeyUp",
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
/// <summary>
/// Defines the <see cref="TabIndex"/> property.
/// </summary>
public static readonly StyledProperty<int> TabIndexProperty =
KeyboardNavigation.TabIndexProperty.AddOwner<InputElement>();
/// <summary>
/// Defines the <see cref="TextInput"/> event.
/// </summary>
@ -426,6 +438,15 @@ namespace Avalonia.Input
internal set { SetAndRaise(IsPointerOverProperty, ref _isPointerOver, value); }
}
/// <summary>
/// Gets or sets a value that indicates whether the control is included in tab navigation.
/// </summary>
public bool IsTabStop
{
get => GetValue(IsTabStopProperty);
set => SetValue(IsTabStopProperty, value);
}
/// <inheritdoc/>
public bool IsEffectivelyEnabled
{
@ -437,6 +458,16 @@ namespace Avalonia.Input
}
}
/// <summary>
/// Gets or sets a value that determines the order in which elements receive focus when the
/// user navigates through controls by pressing the Tab key.
/// </summary>
public int TabIndex
{
get => GetValue(TabIndexProperty);
set => SetValue(TabIndexProperty, value);
}
public List<KeyBinding> KeyBindings { get; } = new List<KeyBinding>();
/// <summary>

32
src/Avalonia.Input/KeyboardNavigation.cs

@ -5,6 +5,14 @@ namespace Avalonia.Input
/// </summary>
public static class KeyboardNavigation
{
/// <summary>
/// Defines the TabIndex attached property.
/// </summary>
public static readonly AttachedProperty<int> TabIndexProperty =
AvaloniaProperty.RegisterAttached<StyledElement, int>(
"TabIndex",
typeof(KeyboardNavigation));
/// <summary>
/// Defines the TabNavigation attached property.
/// </summary>
@ -42,6 +50,26 @@ namespace Avalonia.Input
typeof(KeyboardNavigation),
true);
/// <summary>
/// Gets the <see cref="TabIndexProperty"/> for an element.
/// </summary>
/// <param name="element">The container.</param>
/// <returns>The <see cref="KeyboardNavigationMode"/> for the container.</returns>
public static int GetTabIndex(IInputElement element)
{
return ((IAvaloniaObject)element).GetValue(TabIndexProperty);
}
/// <summary>
/// Sets the <see cref="TabIndexProperty"/> for an element.
/// </summary>
/// <param name="element">The element.</param>
/// <param name="value">The tab index.</param>
public static void SetTabIndex(IInputElement element, int value)
{
((IAvaloniaObject)element).SetValue(TabIndexProperty, value);
}
/// <summary>
/// Gets the <see cref="TabNavigationProperty"/> for a container.
/// </summary>
@ -83,7 +111,7 @@ namespace Avalonia.Input
}
/// <summary>
/// Sets the <see cref="IsTabStopProperty"/> for a container.
/// Sets the <see cref="IsTabStopProperty"/> for an element.
/// </summary>
/// <param name="element">The container.</param>
/// <param name="value">Value indicating whether the container is a tab stop.</param>
@ -93,7 +121,7 @@ namespace Avalonia.Input
}
/// <summary>
/// Gets the <see cref="IsTabStopProperty"/> for a container.
/// Gets the <see cref="IsTabStopProperty"/> for an element.
/// </summary>
/// <param name="element">The container.</param>
/// <returns>Whether the container is a tab stop.</returns>

Loading…
Cancel
Save