diff --git a/tests/Avalonia.Controls.UnitTests/ItemsControlTests.cs b/tests/Avalonia.Controls.UnitTests/ItemsControlTests.cs index 227d783874..73dd0d45ee 100644 --- a/tests/Avalonia.Controls.UnitTests/ItemsControlTests.cs +++ b/tests/Avalonia.Controls.UnitTests/ItemsControlTests.cs @@ -575,6 +575,30 @@ namespace Avalonia.Controls.UnitTests }; } + [Fact] + public void Detaching_Then_Reattaching_To_Logical_Tree_Twice_Does_Not_Throw() + { + // # Issue 3487 + var target = new ItemsControl + { + Template = GetTemplate(), + Items = new[] { "foo", "bar" }, + ItemTemplate = new FuncDataTemplate((_, __) => new Canvas()), + }; + + var root = new TestRoot(target); + root.Measure(Size.Infinity); + root.Arrange(new Rect(root.DesiredSize)); + + root.Child = null; + root.Child = target; + + target.Measure(Size.Infinity); + + root.Child = null; + root.Child = target; + } + private class Item { public Item(string value)