Browse Source

Merge pull request #8890 from DmitryZhelnin/improve-treeview-navigation

TreeView: improve navigation with Left and Right keys
pull/8920/head
Max Katz 4 years ago
committed by GitHub
parent
commit
9aacf436c6
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      src/Avalonia.Controls/TreeView.cs
  2. 19
      src/Avalonia.Controls/TreeViewItem.cs

1
src/Avalonia.Controls/TreeView.cs

@ -495,6 +495,7 @@ namespace Avalonia.Controls
break;
case NavigationDirection.Down:
case NavigationDirection.Right:
if (from?.IsExpanded == true && intoChildren && from.ItemCount > 0)
{
result = (TreeViewItem)from.ItemContainerGenerator.ContainerFromIndex(0)!;

19
src/Avalonia.Controls/TreeViewItem.cs

@ -157,17 +157,26 @@ namespace Avalonia.Controls
switch (e.Key)
{
case Key.Right:
if (Items != null && Items.Cast<object>().Any())
if (Items != null && Items.Cast<object>().Any() && !IsExpanded)
{
IsExpanded = true;
e.Handled = true;
}
e.Handled = true;
break;
case Key.Left:
IsExpanded = false;
e.Handled = true;
if (Items is not null && Items.Cast<object>().Any() && IsExpanded)
{
if (IsFocused)
{
IsExpanded = false;
}
else
{
FocusManager.Instance?.Focus(this, NavigationMethod.Directional);
}
e.Handled = true;
}
break;
}
}

Loading…
Cancel
Save