diff --git a/src/Uno.UI/UI/Xaml/Media/VisualTreeHelper.cs b/src/Uno.UI/UI/Xaml/Media/VisualTreeHelper.cs index 7cb9d58b1813..ec4af5e05f56 100644 --- a/src/Uno.UI/UI/Xaml/Media/VisualTreeHelper.cs +++ b/src/Uno.UI/UI/Xaml/Media/VisualTreeHelper.cs @@ -222,14 +222,28 @@ public static IReadOnlyList GetOpenPopups(Window window) return Array.Empty(); } - private static IReadOnlyList GetOpenFlyoutPopups(XamlRoot xamlRoot) => - GetOpenPopups(xamlRoot.VisualTree) + private static IReadOnlyList 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 GetOpenPopupsForXamlRoot(XamlRoot xamlRoot) + { + if (xamlRoot is null) + { + throw new ArgumentNullException(nameof(xamlRoot)); + } - public static IReadOnlyList GetOpenPopupsForXamlRoot(XamlRoot xamlRoot) => - GetOpenPopups(xamlRoot.VisualTree); + return GetOpenPopups(xamlRoot.VisualTree); + } private static IReadOnlyList GetOpenPopups(VisualTree visualTree) { @@ -261,6 +275,11 @@ private static IReadOnlyList 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; @@ -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;