Skip to content

Commit

Permalink
Merge pull request #18112 from unoplatform/dev/mazi/nre-xamlroot
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund authored Sep 4, 2024
2 parents e637920 + c53c785 commit 05b4e32
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions src/Uno.UI/UI/Xaml/Media/VisualTreeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,28 @@ public static IReadOnlyList<Popup> GetOpenPopups(Window window)
return Array.Empty<Popup>();
}

private static IReadOnlyList<Popup> GetOpenFlyoutPopups(XamlRoot xamlRoot) =>
GetOpenPopups(xamlRoot.VisualTree)
private static IReadOnlyList<Popup> GetOpenFlyoutPopups(XamlRoot xamlRoot)
{
if (xamlRoot is null)
{
throw new ArgumentNullException(nameof(xamlRoot));
}

return GetOpenPopups(xamlRoot.VisualTree)
.Where(p => p.IsForFlyout)
.ToList()
.AsReadOnly();
}

public static IReadOnlyList<Popup> GetOpenPopupsForXamlRoot(XamlRoot xamlRoot)
{
if (xamlRoot is null)
{
throw new ArgumentNullException(nameof(xamlRoot));
}

public static IReadOnlyList<Popup> GetOpenPopupsForXamlRoot(XamlRoot xamlRoot) =>
GetOpenPopups(xamlRoot.VisualTree);
return GetOpenPopups(xamlRoot.VisualTree);
}

private static IReadOnlyList<Popup> GetOpenPopups(VisualTree visualTree)
{
Expand Down Expand Up @@ -261,6 +275,11 @@ private static IReadOnlyList<Popup> GetOpenPopups(VisualTree visualTree)

internal static void CloseAllPopups(XamlRoot xamlRoot)
{
if (xamlRoot is null)
{
throw new ArgumentNullException(nameof(xamlRoot));
}

foreach (var popup in GetOpenPopups(xamlRoot.VisualTree))
{
popup.IsOpen = false;
Expand All @@ -269,6 +288,11 @@ internal static void CloseAllPopups(XamlRoot xamlRoot)

internal static void CloseLightDismissPopups(XamlRoot xamlRoot)
{
if (xamlRoot is null)
{
throw new ArgumentNullException(nameof(xamlRoot));
}

foreach (var popup in GetOpenPopups(xamlRoot.VisualTree).Where(p => p.IsLightDismissEnabled))
{
popup.IsOpen = false;
Expand Down

0 comments on commit 05b4e32

Please sign in to comment.