Skip to content

Flyout stays open after its placement target is removed from the visual tree #26398

Open

Description

@MartinZikmund

Current behavior

Severity: Medium - Anyone removing a flyout's placement target while the flyout is open ends up with an orphaned open flyout (and light-dismiss layer) that stays on screen and keeps the target and owner alive.

When the element a Flyout was shown at (ShowAt(target)) is removed from the visual tree while the flyout is open, the flyout stays open: IsOpen remains true, its content stays loaded, the popup is still listed by VisualTreeHelper.GetOpenPopupsForXamlRoot, and no Closing/Closed events are raised.

Expected behavior

The flyout closes (Opened | Closing | Closed, content unloaded, 0 open popups), as on WinUI.

Backed by WinUI C++ source: FlyoutBase::SetPlacementTarget attaches an Unloaded handler on the placement target that calls Hide() ("Hook up an event handler that will dismiss the flyout if the placement target gets unloaded"): https://github.com/microsoft/microsoft-ui-xaml/blob/main/dxaml/xcp/dxaml/lib/FlyoutBase_Partial.cpp (FlyoutBase::SetPlacementTarget).
The same scenario was also run on real WinUI 3 (WinAppSDK 2.5.1): IsOpen=False, content not loaded, events Opened | Closing | Closed.

How to reproduce it

  1. Create a page with a Grid (host) containing a Button (a1).
  2. Run:
var fly = new Flyout { Content = new Border { Width = 100, Height = 60 } };
fly.ShowAt(a1);
await Task.Delay(500);
host.Children.Remove(a1);
await Task.Delay(700);
// fly.IsOpen: WinUI False, Uno True

Runtime result (Uno Skia desktop, Release build of master 4636b705e97):

isOpen.afterTargetRemoved      = True    (WinUI: False)
openPopups.afterTargetRemoved  = 1       (WinUI: 0)
events                         = Opening | content.Loaded | Opened     (WinUI: ... | Closing | Closed | content.Unloaded)

FlyoutBase.cs is unchanged between that build and current origin/master.

Workaround

Hide the flyout in the target's Unloaded handler.

Works on UWP/WinUI

Yes

Environment

Nuget Package: master 4636b705e97 (net11.0-desktop)

Affected platforms

Skia (Desktop) observed at runtime; the code is shared FlyoutBase, so likely all heads.

Anything else

Root cause (source-backed): FlyoutBase.ShowAtCore only subscribes ActualThemeChanged on the placement target; nothing reacts to the target leaving the tree.
https://github.com/unoplatform/uno/blob/46ea872727d/src/Uno.UI/UI/Xaml/Controls/Flyout/FlyoutBase.cs#L544-L548

Suggested fix: mirror WinUI by subscribing Unloaded on the target next to ActualThemeChanged (and unsubscribing in the same places, around L397 and L441), and call Hide() from the handler.

Activity

  1. added
    kind/bug
    triage/untriaged
    area/skia ✏️
    difficulty/starter 🚀
    area/popups 💬
    on Nov 13, 2026
  2. christo-polydorou commented on Nov 21, 2026

    @christo-polydorou
    Contributor

    I'd like to pick this one up. Here's the plan before I open a PR:

    Fix. Mirror WinUI's FlyoutBase::SetPlacementTarget: while the flyout is open, subscribe to the placement target's Unloaded and call Hide() from it. This goes in FlyoutBase.ShowAtCore, next to the existing ActualThemeChanged subscription. Both handlers are detached in the same two places as today (when Target is reassigned and in Hide), so the target still doesn't keep the flyout alive after it closes.

    Two small details:

    • The handler only calls Hide() when IsOpen is true. That way an unload after the flyout has already closed doesn't raise a second Closing/Closed.
    • Attaching detaches any existing handlers first. Today, when Opening is cancelled, the handlers stay attached, and the next ShowAt would subscribe them a second time.

    Because it goes through the public Hide(), the sequence is Opened | Closing | Closed, the same as the WinUI 3 run in the description. Closing can still be cancelled, as in WinUI.

    Tests (runtime, in Given_Flyout):

    • When_Target_Removed_While_Open_Closes: removing the target closes the flyout. IsOpen becomes false, the content unloads, there are 0 open popups, and the events are Opened | Closing | Closed.
    • When_Target_Removed_After_Closed_No_Extra_Events: removing the target after a normal close raises no extra events.

    Out of scope. #26399 (re-ShowAt at a new target) and #26400 (only one open flyout at a time) need a port of WinUI's open/staged flyout metadata (CheckAndHandleOpenFlyout, staged open from OnPresenterUnloaded). I'll handle those in separate PRs so this one stays a small starter fix. Nothing here should get in the way of that port.

  3. added a commit that references this issue on Nov 23, 2026
    117da26
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 💬area/skia ✏️difficulty/starter 🚀kind/bugtriage/untriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions