Browse Source

Add failing test for clearing templated child's parent.

Steven Kirk 7 years ago
parent
commit
9ccf63d51b

+ 18 - 0
tests/Avalonia.Controls.UnitTests/Primitives/TemplatedControlTests.cs

@@ -160,6 +160,24 @@ namespace Avalonia.Controls.UnitTests.Primitives
             Assert.Equal(target, child.GetLogicalParent());
             Assert.Equal(target, child.GetLogicalParent());
         }
         }
 
 
+        [Fact]
+        public void Changing_Template_Should_Clear_Old_Templated_Childs_Parent()
+        {
+            var target = new TemplatedControl
+            {
+                Template = new FuncControlTemplate(_ => new Decorator())
+            };
+
+            target.ApplyTemplate();
+
+            var child = (Decorator)target.GetVisualChildren().Single();
+
+            target.Template = new FuncControlTemplate(_ => new Canvas());
+            target.ApplyTemplate();
+
+            Assert.Null(child.Parent);
+        }
+
         [Fact]
         [Fact]
         public void Nested_Templated_Control_Should_Not_Have_Template_Applied()
         public void Nested_Templated_Control_Should_Not_Have_Template_Applied()
         {
         {