diff --git a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_Flyout.cs b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_Flyout.cs new file mode 100644 index 000000000000..cdc091e33923 --- /dev/null +++ b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_Flyout.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Private.Infrastructure; +using Windows.UI.Xaml.Controls; + +namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls +{ + [TestClass] + public class Given_Flyout + { + [TestMethod] + [RunsOnUIThread] + public async Task When_Unloaded_Before_Shown() + { + var button = new Button() + { + Flyout = new Flyout + { + Content = new Border { Width = 50, Height = 30 } + } + }; + + TestServices.WindowHelper.WindowContent = button; + + await TestServices.WindowHelper.WaitForIdle(); + + TestServices.WindowHelper.WindowContent = null; + + await TestServices.WindowHelper.WaitForIdle(); + } + } +} diff --git a/src/Uno.UI/UI/Xaml/Controls/Flyout/FlyoutBase.cs b/src/Uno.UI/UI/Xaml/Controls/Flyout/FlyoutBase.cs index 81a05e3e709f..e710f2941dfd 100644 --- a/src/Uno.UI/UI/Xaml/Controls/Flyout/FlyoutBase.cs +++ b/src/Uno.UI/UI/Xaml/Controls/Flyout/FlyoutBase.cs @@ -264,7 +264,10 @@ private void OnPopupClosed(object sender, object e) protected internal virtual void Close() { - _popup.IsOpen = false; + if (_popup != null) + { + _popup.IsOpen = false; + } } protected internal virtual void Open()