Skip to content

Commit 16be314

Browse files
committed
test: Open ContextFlyout on secondary window
1 parent 3ac3e14 commit 16be314

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_Flyout.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,6 +1995,70 @@ public enum VerticalPosition
19951995
BottomFlush,
19961996
BeyondBottom
19971997
}
1998+
1999+
2000+
#if HAS_UNO
2001+
[TestMethod]
2002+
[RunsOnUIThread]
2003+
public async Task When_Shared_ContextFlyout_Opened_In_Second_Window()
2004+
{
2005+
if (!Uno.UI.Xaml.Controls.NativeWindowFactory.SupportsMultipleWindows)
2006+
{
2007+
Assert.Inconclusive("This test can only run in an environment with multiwindow support");
2008+
}
2009+
2010+
// Use a single shared flyout instance (simulates the singleton
2011+
// TextControlCommandBarContextFlyout resource in Generic.xaml).
2012+
var sharedFlyout = new Flyout
2013+
{
2014+
Content = new TextBlock { Text = "Shared" }
2015+
};
2016+
2017+
// --- Window 1: open and close the flyout ---
2018+
var button1 = new Button { Content = "W1" };
2019+
button1.ContextFlyout = sharedFlyout;
2020+
TestServices.WindowHelper.WindowContent = button1;
2021+
await TestServices.WindowHelper.WaitForLoaded(button1);
2022+
2023+
try
2024+
{
2025+
sharedFlyout.ShowAt(button1);
2026+
await TestServices.WindowHelper.WaitForIdle();
2027+
Assert.IsTrue(sharedFlyout.IsOpen, "Flyout should be open in window 1");
2028+
}
2029+
finally
2030+
{
2031+
sharedFlyout.Hide();
2032+
await TestServices.WindowHelper.WaitForIdle();
2033+
}
2034+
2035+
// --- Window 2: open the same flyout on a different target ---
2036+
var window2 = new Window();
2037+
try
2038+
{
2039+
var button2 = new Button { Content = "W2" };
2040+
button2.ContextFlyout = sharedFlyout;
2041+
window2.Content = button2;
2042+
2043+
bool activated = false;
2044+
window2.Activated += (s, e) => activated = true;
2045+
window2.Activate();
2046+
await TestServices.WindowHelper.WaitFor(() => activated);
2047+
await TestServices.WindowHelper.WaitForLoaded(button2);
2048+
2049+
// This must not throw InvalidOperationException("Cannot change XamlRoot for existing element")
2050+
sharedFlyout.ShowAt(button2);
2051+
await TestServices.WindowHelper.WaitForIdle();
2052+
2053+
Assert.IsTrue(sharedFlyout.IsOpen, "Flyout should be open in window 2");
2054+
}
2055+
finally
2056+
{
2057+
sharedFlyout.Hide();
2058+
window2.Close();
2059+
}
2060+
}
2061+
#endif
19982062
}
19992063

20002064
public partial class MyMenuFlyout : MenuFlyout

0 commit comments

Comments
 (0)