summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamantha Houts <samantha@teamredwall.com>2016-03-28 11:03:43 -0700
committerSamantha Houts <samantha@teamredwall.com>2016-03-28 11:03:43 -0700
commit2140ccdc71bede04686317d561987285f131b57f (patch)
treedc4c6a9c3d2b8e6379b7dbd9655aeaa2e54fa6cf
parent7fdd7ed0c2d4d842226eb64131fae3146e095916 (diff)
parent904d06d81269d9b03e148ab1467aeb163c8b736d (diff)
downloadxamarin-forms-2140ccdc71bede04686317d561987285f131b57f.tar.gz
xamarin-forms-2140ccdc71bede04686317d561987285f131b57f.tar.bz2
xamarin-forms-2140ccdc71bede04686317d561987285f131b57f.zip
Merge pull request #22 from xamarin/fix-bz39509
[C]Remove view from previous parent when added to new parent layout
-rw-r--r--Xamarin.Forms.Core.UnitTests/GroupViewUnitTests.cs13
-rw-r--r--Xamarin.Forms.Core/Layout.cs3
2 files changed, 16 insertions, 0 deletions
diff --git a/Xamarin.Forms.Core.UnitTests/GroupViewUnitTests.cs b/Xamarin.Forms.Core.UnitTests/GroupViewUnitTests.cs
index 61e38cf1..fe823b1a 100644
--- a/Xamarin.Forms.Core.UnitTests/GroupViewUnitTests.cs
+++ b/Xamarin.Forms.Core.UnitTests/GroupViewUnitTests.cs
@@ -288,5 +288,18 @@ namespace Xamarin.Forms.Core.UnitTests
Assert.False (added);
Assert.False (removed);
}
+
+ [Test]
+ public void AddToSecondLayoutRemovesFromOriginal()
+ {
+ var child = new BoxView();
+ var layout1 = new NaiveLayout();
+ var layout2 = new NaiveLayout();
+
+ layout1.Children.Add(child);
+ layout2.Children.Add(child);
+
+ Assert.False(layout1.Children.Contains(child));
+ }
}
}
diff --git a/Xamarin.Forms.Core/Layout.cs b/Xamarin.Forms.Core/Layout.cs
index c611777c..a7864070 100644
--- a/Xamarin.Forms.Core/Layout.cs
+++ b/Xamarin.Forms.Core/Layout.cs
@@ -395,6 +395,9 @@ namespace Xamarin.Forms
void OnInternalAdded(View view)
{
+ var parent = view.Parent as Layout;
+ parent?.InternalChildren.Remove(view);
+
OnChildAdded(view);
if (ShouldInvalidateOnChildAdded(view))
InvalidateLayout();