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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
15 additions and
5 deletions
-
src/Avalonia.Controls/TreeView.cs
-
src/Avalonia.Controls/TreeViewItem.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)!; |
|
|
|
|
|
|
|
@ -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; |
|
|
|
} |
|
|
|
} |
|
|
|
|