From c53c785f4b388b42f93a0873807d99ba9a8a9ae8 Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Wed, 4 Sep 2024 14:56:09 +0200 Subject: [PATCH] feat: Throw ArgumentNullException if XamlRoot is not provided to VisualTreeHelper --- src/Uno.UI/UI/Xaml/Media/VisualTreeHelper.cs | 32 +++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) 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;