Skip to content

Commit 583d60d

Browse files
committed
fix: Allow opening default text flyouts in secondary windows
1 parent 16be314 commit 583d60d

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/Uno.UI/UI/Xaml/XamlRoot.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#nullable enable
22

33
using System;
4+
using System.Diagnostics;
45
using Windows.ApplicationModel.DataTransfer.DragDrop.Core;
6+
using Microsoft.UI.Xaml.Controls.Primitives;
57
using Uno.UI.Xaml.Core;
68
using Uno.UI.Xaml.Islands;
79
using Windows.Foundation;
@@ -88,10 +90,15 @@ internal static void SetForElement(DependencyObject element, XamlRoot? currentRo
8890
return;
8991
}
9092

91-
if (currentRoot is not null)
92-
{
93-
throw new InvalidOperationException("Cannot change XamlRoot for existing element");
94-
}
93+
// WinUI uses a debug-only ASSERT in CDependencyObject::SetVisualTree guarded
94+
// by IsActive(): only elements currently in the live tree are checked, and
95+
// FlyoutBase is explicitly exempted. After Hide(), a Popup is no longer active
96+
// so the assert is naturally skipped for it. We mirror that with IsInLiveTree.
97+
Debug.Assert(
98+
currentRoot is null ||
99+
element is FlyoutBase ||
100+
(element is UIElement uiElement && !uiElement.IsInLiveTree),
101+
"Unexpected XamlRoot change for active non-FlyoutBase element");
95102

96103
if (newRoot is not null)
97104
{

0 commit comments

Comments
 (0)