From a0e880581ea1553a5a502114be0af069a3db3fde Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Thu, 1 Sep 2016 21:55:41 +0200 Subject: [PATCH] Use ContentControl in DropDown template. Instead of `ContentPresenter`. This fixes a memory leak whereby `DropDown` wasn't correctly parenting the `Rectangle` created for `SelectionBoxItem` when the selected item is a control. Fixes #706. --- src/Avalonia.Themes.Default/DropDown.xaml | 8 +-- .../DropDownTests.cs | 63 ++++++++++++++++--- 2 files changed, 60 insertions(+), 11 deletions(-) diff --git a/src/Avalonia.Themes.Default/DropDown.xaml b/src/Avalonia.Themes.Default/DropDown.xaml index c33e4af4f4..5a3d44360c 100644 --- a/src/Avalonia.Themes.Default/DropDown.xaml +++ b/src/Avalonia.Themes.Default/DropDown.xaml @@ -10,10 +10,10 @@ BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"> - + { }; + + root.Child = null; + + Assert.False(((ILogical)target).IsAttachedToLogicalTree); + Assert.False(((ILogical)rectangle).IsAttachedToLogicalTree); + } + private FuncControlTemplate GetTemplate() { return new FuncControlTemplate(parent => @@ -26,8 +71,7 @@ namespace Avalonia.Controls.UnitTests { new ContentControl { - Name = "contentControl", - [~ContentPresenter.ContentProperty] = parent[~DropDown.SelectionBoxItemProperty], + [!ContentControl.ContentProperty] = parent[!DropDown.SelectionBoxItemProperty], }, new ToggleButton { @@ -35,7 +79,12 @@ namespace Avalonia.Controls.UnitTests }, new Popup { - Name = "popup", + Name = "PART_Popup", + Child = new ItemsPresenter + { + Name = "PART_ItemsPresenter", + [!ItemsPresenter.ItemsProperty] = parent[!DropDown.ItemsProperty], + } } } };