diff --git a/src/Controls/tests/Core.UnitTests/TestClasses/TestWindow.cs b/src/Controls/tests/Core.UnitTests/TestClasses/TestWindow.cs index 804d68c13459..bd351d85adbc 100644 --- a/src/Controls/tests/Core.UnitTests/TestClasses/TestWindow.cs +++ b/src/Controls/tests/Core.UnitTests/TestClasses/TestWindow.cs @@ -2,13 +2,14 @@ using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; namespace Microsoft.Maui.Controls.Core.UnitTests { public class TestWindow : Window { + // Because the relationship from Window => Application is a weakreference + // we need to retain a reference to the Application so it doesn't get GC'd + TestApp _app; public TestWindow() { @@ -24,12 +25,10 @@ protected override void OnPropertyChanged([CallerMemberName] string propertyName if (propertyName == PageProperty.PropertyName && Parent == null) { - var app = new TestApp(this); - _ = (app as IApplication).CreateWindow(null); + _app = new TestApp(this); + _ = (_app as IApplication).CreateWindow(null); } } - - } public static class TestWindowExtensions