Skip to content

Opening an unrelated flyout doesn't close the one already open (WinUI allows only one) #26400

Open

Description

@MartinZikmund

Current behavior 🐛

Severity: Medium - any app that opens a second, unrelated flyout or context menu (or switches MenuBar menus programmatically / via UI Automation) ends up with several light-dismiss popups on screen at once, and the first flyout never raises Closing/Closed.

Calling ShowAt on a flyout while a different, unrelated flyout is open leaves both open:

  • flyoutA.IsOpen stays true, flyoutB.IsOpen is true
  • VisualTreeHelper.GetOpenPopupsForXamlRoot(...) returns 2 popups
  • event sequence is A.Opened | B.Opened (no A.Closing / A.Closed)

The same happens for every combination of Flyout and MenuFlyout (Flyout+Flyout, MenuFlyout+MenuFlyout, Flyout+MenuFlyout, MenuFlyout+Flyout).

It also affects MenuBar: expanding the "Edit" MenuBarItem through its automation peer (IExpandCollapseProvider.Expand()) while "File" is open leaves "File" Expanded too, with 2 open popups.

Expected behavior 🎯

WinUI tracks one open flyout (plus one "staged" flyout) per flyout metadata scope. When a different flyout is shown while one is open, the open one is hidden and the new one is staged; once the old presenter unloads, the staged flyout opens. Child flyouts (opened from inside another flyout) use the parent's own metadata, so nesting keeps working.

Expected results (recorded on WinUI 3 / Windows App SDK with the same scenarios):

Scenario WinUI Uno
A.IsOpen after B.ShowAt False True
open popups 1 2
events A.Opened | A.Closing | A.Closed | B.Opened A.Opened | B.Opened
MenuBar: expand Edit while File open, File state Collapsed Expanded

How to reproduce it (as minimally and precisely as possible) 🔬

  1. Create an app with two buttons a1, a2 in a StackPanel.
  2. Run:
var fa = new Flyout { Content = new TextBlock { Text = "A" } };
var fb = new Flyout { Content = new TextBlock { Text = "B" } };
fa.Closed += (s, e) => Debug.WriteLine("A.Closed");

fa.ShowAt(a1);
await Task.Delay(500);
fb.ShowAt(a2);
await Task.Delay(700);

Debug.WriteLine($"A.IsOpen={fa.IsOpen}");                                            // WinUI: False, Uno: True
Debug.WriteLine(VisualTreeHelper.GetOpenPopupsForXamlRoot(a1.XamlRoot).Count);       // WinUI: 1,     Uno: 2
  1. Observe both flyouts are visible and A.Closed is never raised.

MenuBar variant:

var mb = new MenuBar();
var file = new MenuBarItem { Title = "File" }; file.Items.Add(new MenuFlyoutItem { Text = "New" });
var edit = new MenuBarItem { Title = "Edit" }; edit.Items.Add(new MenuFlyoutItem { Text = "Cut" });
mb.Items.Add(file); mb.Items.Add(edit);
// after mb is loaded:
var pf = (IExpandCollapseProvider)FrameworkElementAutomationPeer.CreatePeerForElement(file).GetPattern(PatternInterface.ExpandCollapse);
var pe = (IExpandCollapseProvider)FrameworkElementAutomationPeer.CreatePeerForElement(edit).GetPattern(PatternInterface.ExpandCollapse);
pf.Expand(); await Task.Delay(500);
pe.Expand(); await Task.Delay(500);
// pf.ExpandCollapseState: WinUI Collapsed, Uno Expanded; open popups: WinUI 1, Uno 2

Runtime test used to verify this (fails on Uno, all 5 cases):

Given_Flyout_UnrelatedOpen.cs
[TestClass]
[RunsOnUIThread]
public class Given_Flyout_UnrelatedOpen
{
	[TestMethod]
	[DataRow(false, false)]
	[DataRow(true, true)]
	[DataRow(false, true)]
	[DataRow(true, false)]
	public async Task When_Unrelated_Flyout_Opened_First_Closes(bool aIsMenu, bool bIsMenu)
	{
		var a1 = new Button { Content = "a1" };
		var a2 = new Button { Content = "a2" };
		WindowHelper.WindowContent = new StackPanel { Children = { a1, a2 } };
		await WindowHelper.WaitForLoaded(a2);

		FlyoutBase fa = aIsMenu ? new MenuFlyout { Items = { new MenuFlyoutItem { Text = "A" } } } : new Flyout { Content = new TextBlock { Text = "A" } };
		FlyoutBase fb = bIsMenu ? new MenuFlyout { Items = { new MenuFlyoutItem { Text = "B" } } } : new Flyout { Content = new TextBlock { Text = "B" } };
		List<string> events = new();
		fa.Opened += (s, e) => events.Add("A.Opened");
		fa.Closing += (s, e) => events.Add("A.Closing");
		fa.Closed += (s, e) => events.Add("A.Closed");
		fb.Opened += (s, e) => events.Add("B.Opened");

		try
		{
			fa.ShowAt(a1);
			await WindowHelper.WaitFor(() => events.Contains("A.Opened"));
			fb.ShowAt(a2);
			await WindowHelper.WaitFor(() => events.Contains("B.Opened"));
			await WindowHelper.WaitForIdle();

			var popups = VisualTreeHelper.GetOpenPopupsForXamlRoot(a1.XamlRoot).Count;
			var log = $"A.IsOpen={fa.IsOpen} B.IsOpen={fb.IsOpen} popups={popups} events={string.Join(" | ", events)}";
			Assert.IsFalse(fa.IsOpen, log);
			Assert.IsTrue(fb.IsOpen, log);
			Assert.AreEqual(1, popups, log);
			CollectionAssert.AreEqual(new[] { "A.Opened", "A.Closing", "A.Closed", "B.Opened" }, events, log);
		}
		finally
		{
			fa.Hide();
			fb.Hide();
		}
	}

	[TestMethod]
	public async Task When_MenuBarItem_Expanded_Other_Collapses()
	{
		var mb = new MenuBar { HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top, Width = 500 };
		var file = new MenuBarItem { Title = "File" };
		file.Items.Add(new MenuFlyoutItem { Text = "New" });
		var edit = new MenuBarItem { Title = "Edit" };
		edit.Items.Add(new MenuFlyoutItem { Text = "Cut" });
		mb.Items.Add(file);
		mb.Items.Add(edit);
		WindowHelper.WindowContent = mb;
		await WindowHelper.WaitForLoaded(mb);
		await WindowHelper.WaitForIdle();

		var pf = FrameworkElementAutomationPeer.CreatePeerForElement(file).GetPattern(PatternInterface.ExpandCollapse) as IExpandCollapseProvider;
		var pe = FrameworkElementAutomationPeer.CreatePeerForElement(edit).GetPattern(PatternInterface.ExpandCollapse) as IExpandCollapseProvider;

		try
		{
			pf.Expand();
			await Task.Delay(500);
			await WindowHelper.WaitForIdle();
			pe.Expand();
			await Task.Delay(500);
			await WindowHelper.WaitForIdle();

			var popups = VisualTreeHelper.GetOpenPopupsForXamlRoot(mb.XamlRoot).Count;
			var log = $"file={pf.ExpandCollapseState} edit={pe.ExpandCollapseState} popups={popups}";
			Assert.AreEqual(ExpandCollapseState.Collapsed, pf.ExpandCollapseState, log);
			Assert.AreEqual(ExpandCollapseState.Expanded, pe.ExpandCollapseState, log);
			Assert.AreEqual(1, popups, log);
		}
		finally
		{
			pe.Collapse();
			pf.Collapse();
			await WindowHelper.WaitForIdle();
		}
	}
}

Uno result: every When_Unrelated_Flyout_Opened_First_Closes case fails with A.IsOpen=True B.IsOpen=True popups=2 events=A.Opened | B.Opened; When_MenuBarItem_Expanded_Other_Collapses fails with file=Expanded edit=Expanded popups=2.

Workaround 🛠️

Hide any open flyout yourself before showing another one (e.g. keep a reference to the last opened flyout and call Hide() on it first).

Affected platforms 📱💻🖥️

Skia (Windows), runtime-verified. All other platforms by code inspection: the logic is in shared FlyoutBase code.

Uno.Sdk version (and other relevant versions) 📦

Built from source, master at 46ea872 (net11.0-desktop). WinUI comparison: Windows App SDK 2.5.1. Works on WinUI: yes.

IDE version 🧑‍💻

No response

Anything else we need to know? 💬

What was verified and how

  • Uno, runtime: the runtime test above, run on Skia Desktop (Win32) built from master 46ea872. All 5 cases fail as described.
  • WinUI, runtime: the same scenarios (Flyout/MenuFlyout pairs and the MenuBar UIA expand) were run in a native WinUI 3 app (Windows App SDK 2.5.1) and produced the "WinUI" column of the table above.
  • WinUI, source: the behavior is explicit in FlyoutBase_partial.cpp.

WinUI implementation

Uno implementation

FlyoutBase.ShowAtCore only handles "this same flyout is already open". The static _openFlyouts list is only used to close flyouts opened after the one being hidden (Hide). Nothing closes an open flyout that isn't an ancestor of the new one.

Suggested fix

Port WinUI's FlyoutMetadata (open + staged flyout, with per-parent child metadata) and CheckAndHandleOpenFlyout / the staged-open in OnPresenterUnloaded, replacing the ad-hoc _openFlyouts list.

Related (same open/staged-flyout bookkeeping):

Activity

  1. added
    kind/bug
    triage/untriaged
    platform/all
    difficulty/medium 🤔
    area/popups 💬
    on Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/popups 💬difficulty/medium 🤔kind/bugplatform/alltriage/untriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions