From b89d75f43a1e25dd34bd2cdd871f422fc3b64ee7 Mon Sep 17 00:00:00 2001 From: donandren Date: Sun, 26 Jun 2016 02:02:16 +0300 Subject: [PATCH] Fixed ContentPresenter add/remove from logicalchildren otside teamplate --- .../Presenters/ContentPresenter.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Controls/Presenters/ContentPresenter.cs b/src/Avalonia.Controls/Presenters/ContentPresenter.cs index ca02a0505c..c5a8337339 100644 --- a/src/Avalonia.Controls/Presenters/ContentPresenter.cs +++ b/src/Avalonia.Controls/Presenters/ContentPresenter.cs @@ -279,12 +279,21 @@ namespace Avalonia.Controls.Presenters if (oldChild?.LogicalParent == this) { - ((ISetLogicalParent)oldChild).SetParent(null); + LogicalChildren.Remove(oldChild); } if (newChild.Parent == null) { - ((ISetLogicalParent)newChild).SetParent((ILogical)this.TemplatedParent ?? this); + var templatedLogicalParent = TemplatedParent as ILogical; + + if (templatedLogicalParent != null) + { + ((ISetLogicalParent)newChild).SetParent(templatedLogicalParent); + } + else + { + LogicalChildren.Add(newChild); + } } VisualChildren.Add(newChild);