Skip to content

Commit

Permalink
Merge pull request #10818 from unoplatform/dev/xygu/20221223/flyout-x…
Browse files Browse the repository at this point in the history
…amlroot
  • Loading branch information
Xiaoy312 authored Dec 24, 2022
2 parents 8c62ee2 + 2dbc661 commit 1c9cb42
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/Flyout/FlyoutBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -234,6 +235,8 @@ private void OnAllowFocusOnInteractionChanged(bool oldValue, bool newValue) =>

public FrameworkElement Target { get; private set; }

public XamlRoot XamlRoot { get; set; }

/// <summary>
/// Defines an optional position of the popup in the <see cref="Target"/> element.
/// </summary>
Expand Down Expand Up @@ -297,6 +300,7 @@ private protected virtual void ShowAtCore(FrameworkElement placementTarget, Flyo
}

Target = placementTarget;
XamlRoot = placementTarget?.XamlRoot;
_popup.PlacementTarget = placementTarget;

if (showOptions != null)
Expand Down

0 comments on commit 1c9cb42

Please sign in to comment.