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 index e9e8b55f6412..30223666c73c 100644 --- 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 @@ -715,6 +715,34 @@ void OnClosing(object sender, FlyoutBaseClosingEventArgs args) } } + [TestMethod] + public async Task When_Opening_XamlRootIsSet() + { + var flyout = new Flyout(); + try + { + var host = new Button() { Content = "Asd" }; + TestServices.WindowHelper.WindowContent = host; + await TestServices.WindowHelper.WaitForIdle(); + await TestServices.WindowHelper.WaitForLoaded(host); + + var capture = default(XamlRoot); + + flyout.Opening += (s, e) => capture = (s as Flyout).XamlRoot; + + flyout.ShowAt(host); + await TestServices.WindowHelper.WaitForIdle(); + await TestServices.WindowHelper.WaitForIdle(); + flyout.Hide(); + + Assert.AreEqual(host.XamlRoot, capture, "Flyout did not inherit the XamlRoot from its placementTarget."); + } + finally + { + flyout.Hide(); + } + } + private static void VerifyRelativeContentPosition(HorizontalPosition horizontalPosition, VerticalPosition verticalPosition, FrameworkElement content, double minimumTargetOffset, FrameworkElement target) { var contentScreenBounds = content.GetOnScreenBounds(); diff --git a/src/Uno.UI/Generated/3.0.0.0/Windows.UI.Xaml.Controls.Primitives/FlyoutBase.cs b/src/Uno.UI/Generated/3.0.0.0/Windows.UI.Xaml.Controls.Primitives/FlyoutBase.cs index c3244c7262b0..41cb9d622120 100644 --- a/src/Uno.UI/Generated/3.0.0.0/Windows.UI.Xaml.Controls.Primitives/FlyoutBase.cs +++ b/src/Uno.UI/Generated/3.0.0.0/Windows.UI.Xaml.Controls.Primitives/FlyoutBase.cs @@ -81,20 +81,6 @@ public bool InputDevicePrefersPrimaryCommands // Skipping already declared property IsOpen #if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__ [global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")] - public global::Windows.UI.Xaml.XamlRoot XamlRoot - { - get - { - throw new global::System.NotImplementedException("The member XamlRoot FlyoutBase.XamlRoot is not implemented in Uno."); - } - set - { - global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.UI.Xaml.Controls.Primitives.FlyoutBase", "XamlRoot FlyoutBase.XamlRoot"); - } - } - #endif - #if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__ - [global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")] public bool ShouldConstrainToRootBounds { get diff --git a/src/Uno.UI/UI/Xaml/Controls/Flyout/FlyoutBase.cs b/src/Uno.UI/UI/Xaml/Controls/Flyout/FlyoutBase.cs index a6159a8496b2..08b3697f1c44 100644 --- a/src/Uno.UI/UI/Xaml/Controls/Flyout/FlyoutBase.cs +++ b/src/Uno.UI/UI/Xaml/Controls/Flyout/FlyoutBase.cs @@ -13,6 +13,7 @@ using Windows.Foundation; using Windows.UI.Core; using Windows.UI.ViewManagement; +using Windows.UI.Xaml; using Windows.UI.Xaml.Media; #if XAMARIN_IOS @@ -234,6 +235,8 @@ private void OnAllowFocusOnInteractionChanged(bool oldValue, bool newValue) => public FrameworkElement Target { get; private set; } + public XamlRoot XamlRoot { get; set; } + /// /// Defines an optional position of the popup in the element. /// @@ -297,6 +300,7 @@ private protected virtual void ShowAtCore(FrameworkElement placementTarget, Flyo } Target = placementTarget; + XamlRoot = placementTarget?.XamlRoot; _popup.PlacementTarget = placementTarget; if (showOptions != null)