Skip to content

Commit 11f18e0

Browse files
committed
Merge pull request #5949 from MarchingCube/ux-treepage-highlight
Fix devtools selection highlight requiring direct hover over the control
1 parent 7efb119 commit 11f18e0

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/Avalonia.Diagnostics/Diagnostics/Views/TreePageView.xaml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<TreeView.Styles>
2121
<Style Selector="TreeViewItem">
2222
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
23+
<Setter Property="Background" Value="Transparent" />
2324
</Style>
2425
</TreeView.Styles>
2526
</TreeView>

src/Avalonia.Diagnostics/Diagnostics/Views/TreePageView.xaml.cs

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Diagnostics;
12
using System.Linq;
23
using Avalonia.Controls;
34
using Avalonia.Controls.Generators;
@@ -6,6 +7,7 @@
67
using Avalonia.Input;
78
using Avalonia.Markup.Xaml;
89
using Avalonia.Media;
10+
using Avalonia.VisualTree;
911

1012
namespace Avalonia.Diagnostics.Views
1113
{
@@ -100,12 +102,19 @@ private void TreeViewItemMaterialized(object sender, ItemContainerEventArgs e)
100102
private void TreeViewItemTemplateApplied(object sender, TemplateAppliedEventArgs e)
101103
{
102104
var item = (TreeViewItem)sender;
103-
var headerPresenter = item.HeaderPresenter;
104-
headerPresenter.ApplyTemplate();
105105

106-
var header = headerPresenter.Child;
107-
header.PointerEnter += AddAdorner;
108-
header.PointerLeave += RemoveAdorner;
106+
// This depends on the default tree item template.
107+
// We want to handle events in the item header but exclude events coming from children.
108+
var header = item.FindDescendantOfType<Border>();
109+
110+
Debug.Assert(header != null);
111+
112+
if (header != null)
113+
{
114+
header.PointerEnter += AddAdorner;
115+
header.PointerLeave += RemoveAdorner;
116+
}
117+
109118
item.TemplateApplied -= TreeViewItemTemplateApplied;
110119
}
111120
}

0 commit comments

Comments
 (0)