Browse Source

Check for empty items in GetContainerInDirection.

Don't try to navigate into `TreeViewItem`s with no children: this causes a out-of-range exception.

Fixes #2980
pull/3077/head
Steven Kirk 7 years ago
parent
commit
75fdd0d343
  1. 5
      src/Avalonia.Controls/TreeView.cs

5
src/Avalonia.Controls/TreeView.cs

@ -1,3 +1,4 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
@ -470,7 +471,7 @@ namespace Avalonia.Controls
if (index > 0)
{
var previous = (TreeViewItem)parentGenerator.ContainerFromIndex(index - 1);
result = previous.IsExpanded ?
result = previous.IsExpanded && previous.ItemCount > 0 ?
(TreeViewItem)previous.ItemContainerGenerator.ContainerFromIndex(previous.ItemCount - 1) :
previous;
}
@ -482,7 +483,7 @@ namespace Avalonia.Controls
break;
case NavigationDirection.Down:
if (from.IsExpanded && intoChildren)
if (from.IsExpanded && intoChildren && from.ItemCount > 0)
{
result = (TreeViewItem)from.ItemContainerGenerator.ContainerFromIndex(0);
}

Loading…
Cancel
Save