Skip to content

Commit

Permalink
feat: Throw ArgumentNullException if XamlRoot is not provided to Visu…
Browse files Browse the repository at this point in the history
…alTreeHelper
  • Loading branch information
MartinZikmund committed Sep 4, 2024
1 parent 4fa5f6a commit c53c785
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 c53c785

Please sign in to comment.