From 0d76ec30e2df25a418a83aaf07bb0eec7eaff872 Mon Sep 17 00:00:00 2001 From: "Felix Hartmann (PEA3-Fe-FI)" Date: Thu, 23 Sep 2021 13:29:04 +0200 Subject: [PATCH] only open dialog if there are no popups already open --- PolyChat/MainPage.xaml.cs | 29 +++++++++++++++++++++++++---- PolyChat/PolyChat.csproj | 3 --- PolyChat/Views/Dialog.xaml.cs | 3 ++- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/PolyChat/MainPage.xaml.cs b/PolyChat/MainPage.xaml.cs index f918ff3..e35e422 100644 --- a/PolyChat/MainPage.xaml.cs +++ b/PolyChat/MainPage.xaml.cs @@ -7,11 +7,11 @@ using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; using System.Text.Json; -using System.Threading.Tasks; +using Windows.Foundation; using Windows.UI.Core; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Data; +using Windows.UI.Xaml.Media; // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 @@ -90,7 +90,7 @@ namespace PolyChat DateTime.Now ); NewChatDialog dialog = new NewChatDialog(); - var result = await dialog.ShowAsync(); + var result = await SafelyOpenDialog(dialog); if (result == ContentDialogResult.Primary) { string ip = IP.GetIPFromCode(dialog.getValue()); @@ -106,7 +106,7 @@ namespace PolyChat public async void OnOpenEditUsernameDialog(object sender = null, RoutedEventArgs e = null) { EditUsernameDialog dialog = new EditUsernameDialog(username); - var result = await dialog.ShowAsync(); + var result = await SafelyOpenDialog(dialog); if (result == ContentDialogResult.Primary) { username = dialog.getValue(); @@ -220,6 +220,27 @@ namespace PolyChat } } + public static IAsyncOperation SafelyOpenDialog(Dialog d) + { + if(VisualTreeHelper.GetOpenPopups(Window.Current).Count == 0) + return d.ShowAsync(); + return null; + } + + public static IAsyncOperation SafelyOpenDialog(NewChatDialog d) + { + if (VisualTreeHelper.GetOpenPopups(Window.Current).Count == 0) + return d.ShowAsync(); + return null; + } + + public static IAsyncOperation SafelyOpenDialog(EditUsernameDialog d) + { + if (VisualTreeHelper.GetOpenPopups(Window.Current).Count == 0) + return d.ShowAsync(); + return null; + } + // UPDATE FUNCTIONS FOR UI PLACEHOLDERS private void updateNoChatsPlaceholder() diff --git a/PolyChat/PolyChat.csproj b/PolyChat/PolyChat.csproj index c047509..df5e9f4 100644 --- a/PolyChat/PolyChat.csproj +++ b/PolyChat/PolyChat.csproj @@ -204,9 +204,6 @@ 5.0.2 - - - 14.0 diff --git a/PolyChat/Views/Dialog.xaml.cs b/PolyChat/Views/Dialog.xaml.cs index f342693..331fb6f 100644 --- a/PolyChat/Views/Dialog.xaml.cs +++ b/PolyChat/Views/Dialog.xaml.cs @@ -3,6 +3,7 @@ using PolyChat.Util; using System; using System.Collections.ObjectModel; using System.Linq; +using System.Threading; using Windows.Foundation; using Windows.UI.Core; using Windows.UI.Popups; @@ -34,7 +35,7 @@ namespace PolyChat.Views Primary = primary.Action; Secondary = secondary.Action; // show - ShowDialogAsync(); + MainPage.SafelyOpenDialog(this); } private void setType(string type, string message)