From ba89e646c4c7b3e0143b1353a562889876515d37 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Fri, 11 Nov 2016 21:01:51 +0000 Subject: [PATCH] ItemsControl uses the ContainerType property to check if its a typed container. --- src/Avalonia.Controls/ItemsControl.cs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/Avalonia.Controls/ItemsControl.cs b/src/Avalonia.Controls/ItemsControl.cs index 1c6afa4279..c3c78e9e88 100644 --- a/src/Avalonia.Controls/ItemsControl.cs +++ b/src/Avalonia.Controls/ItemsControl.cs @@ -14,6 +14,8 @@ using Avalonia.Controls.Templates; using Avalonia.Controls.Utils; using Avalonia.LogicalTree; using Avalonia.Metadata; +using System; + namespace Avalonia.Controls { @@ -219,6 +221,7 @@ namespace Avalonia.Controls return new ItemContainerGenerator(this); } + /// /// Called when new containers are materialized for the by its /// . @@ -229,13 +232,20 @@ namespace Avalonia.Controls var toAdd = new List(); foreach (var container in e.Containers) - { + { // If the item is its own container, then it will be added to the logical tree when // it was added to the Items collection. if (container.ContainerControl != null && container.ContainerControl != container.Item) { - (container.ContainerControl as ContentPresenter).UpdateChild(); - toAdd.Add((container.ContainerControl as ContentPresenter).Child as ILogical); + if (ItemContainerGenerator.ContainerType == null) + { + (container.ContainerControl as ContentPresenter).UpdateChild(); + toAdd.Add((container.ContainerControl as ContentPresenter).Child as ILogical); + } + else + { + toAdd.Add(container.ContainerControl); + } } } @@ -257,7 +267,14 @@ namespace Avalonia.Controls // when it is removed from the Items collection. if (container?.ContainerControl != container?.Item) { - toRemove.Add((container.ContainerControl as ContentPresenter).Child); + if (ItemContainerGenerator.ContainerType == null) + { + toRemove.Add((container.ContainerControl as ContentPresenter).Child); + } + else + { + toRemove.Add(container.ContainerControl); + } } }