From 0b00af4f898043b03633b100993206db6c93f05c Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Fri, 20 Aug 2021 21:51:45 +0200 Subject: [PATCH] fix: Hide open flyouts when MessageDialog is shown --- src/Uno.UI/UI/Xaml/Application.cs | 3 ++- .../DispatcherTimerProxy.cs} | 6 ++---- src/Uno.UWP/Helpers/VisualTreeHelperProxy.cs | 15 +++++++++++++++ src/Uno.UWP/UI/Popups/MessageDialog.cs | 3 +++ 4 files changed, 22 insertions(+), 5 deletions(-) rename src/Uno.UWP/{Uno/DispatcherTimerHelper.cs => Helpers/DispatcherTimerProxy.cs} (77%) create mode 100644 src/Uno.UWP/Helpers/VisualTreeHelperProxy.cs diff --git a/src/Uno.UI/UI/Xaml/Application.cs b/src/Uno.UI/UI/Xaml/Application.cs index 7f5ef15e00fc..5dc1debb56ed 100644 --- a/src/Uno.UI/UI/Xaml/Application.cs +++ b/src/Uno.UI/UI/Xaml/Application.cs @@ -55,7 +55,8 @@ static Application() ApiInformation.RegisterAssembly(typeof(Application).Assembly); ApiInformation.RegisterAssembly(typeof(Windows.Storage.ApplicationData).Assembly); - Uno.DispatcherTimerHelper.SetDispatcherTimerGetter(() => new DispatcherTimer()); + Uno.Helpers.DispatcherTimerProxy.SetDispatcherTimerGetter(() => new DispatcherTimer()); + Uno.Helpers.VisualTreeHelperProxy.SetCloseAllPopupsAction(() => Media.VisualTreeHelper.CloseAllPopups()); InitializePartialStatic(); } diff --git a/src/Uno.UWP/Uno/DispatcherTimerHelper.cs b/src/Uno.UWP/Helpers/DispatcherTimerProxy.cs similarity index 77% rename from src/Uno.UWP/Uno/DispatcherTimerHelper.cs rename to src/Uno.UWP/Helpers/DispatcherTimerProxy.cs index 4fa65f4a6f01..a9d16c59cee4 100644 --- a/src/Uno.UWP/Uno/DispatcherTimerHelper.cs +++ b/src/Uno.UWP/Helpers/DispatcherTimerProxy.cs @@ -1,12 +1,10 @@ #nullable enable using System; -using System.Collections.Generic; -using System.Text; -namespace Uno +namespace Uno.Helpers { - internal static class DispatcherTimerHelper + internal static class DispatcherTimerProxy { private static Func? _getter; diff --git a/src/Uno.UWP/Helpers/VisualTreeHelperProxy.cs b/src/Uno.UWP/Helpers/VisualTreeHelperProxy.cs new file mode 100644 index 000000000000..f6806ad62a44 --- /dev/null +++ b/src/Uno.UWP/Helpers/VisualTreeHelperProxy.cs @@ -0,0 +1,15 @@ +#nullable enable + +using System; + +namespace Uno.Helpers +{ + internal static class VisualTreeHelperProxy + { + private static Action? _closeAllPopups; + + public static void CloseAllPopups() => _closeAllPopups?.Invoke(); + + public static void SetCloseAllPopupsAction(Action closeAllPopups) => _closeAllPopups = closeAllPopups; + } +} diff --git a/src/Uno.UWP/UI/Popups/MessageDialog.cs b/src/Uno.UWP/UI/Popups/MessageDialog.cs index 85ac33e008ec..a2d77c5d824b 100644 --- a/src/Uno.UWP/UI/Popups/MessageDialog.cs +++ b/src/Uno.UWP/UI/Popups/MessageDialog.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; +using Uno.Helpers; using Windows.Foundation; using Windows.UI.Core; @@ -52,6 +53,8 @@ public MessageDialog(string content, string title) public IAsyncOperation ShowAsync() { + VisualTreeHelperProxy.CloseAllPopups(); + var invokedCommand = new TaskCompletionSource(); return AsyncOperation.FromTask(async ct =>