From 91b6a4204e3854cf39960d2a85298526f4f4ce51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Kaan=20K=C3=B6se?= Date: Sat, 13 Jul 2024 18:36:35 +0200 Subject: [PATCH] Fixing dialog presentations. --- Wino.Mail/Services/DialogService.cs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Wino.Mail/Services/DialogService.cs b/Wino.Mail/Services/DialogService.cs index c3e3fda9..686398bf 100644 --- a/Wino.Mail/Services/DialogService.cs +++ b/Wino.Mail/Services/DialogService.cs @@ -20,6 +20,8 @@ using Wino.Core.Requests; using Wino.Core.UWP.Extensions; using Wino.Dialogs; using Wino.Helpers; +using Windows.Foundation.Metadata; +using Wino.Core.WinUI.Services; #if NET8_0 using Microsoft.UI.Xaml.Controls; @@ -34,10 +36,12 @@ namespace Wino.Services private SemaphoreSlim _presentationSemaphore = new SemaphoreSlim(1); private readonly IThemeService _themeService; + private readonly IAppShellService _appShellService; - public DialogService(IThemeService themeService) + public DialogService(IThemeService themeService, IAppShellService appShellService) { _themeService = themeService; + _appShellService = appShellService; } public void ShowNotSupportedMessage() @@ -52,9 +56,21 @@ namespace Wino.Services RequestedTheme = _themeService.RootTheme.ToWindowsElementTheme() }; +#if NET8_0 + AssignXamlRoot(dialog); +#endif + await HandleDialogPresentation(() => dialog.ShowDialogAsync(title, message)); } + private void AssignXamlRoot(ContentDialog dialog) + { + if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8)) + { + dialog.XamlRoot = (_appShellService.AppWindow.Content).XamlRoot; + } + } + /// /// Waits for PopupRoot to be available before presenting the dialog and returns the result after presentation. /// @@ -66,6 +82,9 @@ namespace Wino.Services try { +#if NET8_0 + AssignXamlRoot(dialog); +#endif return await dialog.ShowAsync(); } catch (Exception ex)