From d3b43efe161c3ff12cd8939cff6a821bbc8f94aa Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Thu, 29 Oct 2020 11:33:41 +0000 Subject: [PATCH] if TreeView has a selecteditem that isnt really part of the tree... then do not crash tab navigation. --- src/Avalonia.Controls/TreeView.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Controls/TreeView.cs b/src/Avalonia.Controls/TreeView.cs index b2bd5ab2e5..f020280496 100644 --- a/src/Avalonia.Controls/TreeView.cs +++ b/src/Avalonia.Controls/TreeView.cs @@ -378,10 +378,11 @@ namespace Avalonia.Controls { if (!this.IsVisualAncestorOf(element)) { - IControl result = _selectedItem != null ? + var result = _selectedItem != null ? ItemContainerGenerator.Index.ContainerFromItem(_selectedItem) : ItemContainerGenerator.ContainerFromIndex(0); - return (true, result); + + return (result is {}, result); // SelectedItem may not be in the treeview. } return (true, null);