diff --git a/src/Maui/Prism.Maui/PrismAppBuilder.cs b/src/Maui/Prism.Maui/PrismAppBuilder.cs index 2519894c02..cf15cd6025 100644 --- a/src/Maui/Prism.Maui/PrismAppBuilder.cs +++ b/src/Maui/Prism.Maui/PrismAppBuilder.cs @@ -289,7 +289,7 @@ private void RegisterDefaultRequiredTypes(IContainerRegistry containerRegistry) { containerRegistry.TryRegisterSingleton(); containerRegistry.TryRegisterSingleton(); - containerRegistry.TryRegisterScoped(); + containerRegistry.TryRegisterSingleton(); containerRegistry.TryRegisterScoped(); containerRegistry.TryRegister(); containerRegistry.RegisterDialogContainer(); diff --git a/src/Maui/Prism.Maui/Services/PageDialogs/PageDialogService.cs b/src/Maui/Prism.Maui/Services/PageDialogs/PageDialogService.cs index 6e761eca35..a6bfd54dde 100644 --- a/src/Maui/Prism.Maui/Services/PageDialogs/PageDialogService.cs +++ b/src/Maui/Prism.Maui/Services/PageDialogs/PageDialogService.cs @@ -1,5 +1,6 @@ using Prism.AppModel; using Prism.Common; +using Prism.Navigation; using FlowDirection = Prism.AppModel.FlowDirection; using MauiFlow = Microsoft.Maui.FlowDirection; @@ -10,7 +11,7 @@ namespace Prism.Services; /// public class PageDialogService : IPageDialogService { - private IPageAccessor _pageAccessor { get; } + private IWindowManager _windowManager { get; } /// /// Gets the . /// @@ -19,11 +20,11 @@ public class PageDialogService : IPageDialogService /// /// Creates a new /// - /// The . + /// The . /// The . - public PageDialogService(IPageAccessor pageAccessor, IKeyboardMapper keyboardMapper) + public PageDialogService(IWindowManager windowManager, IKeyboardMapper keyboardMapper) { - _pageAccessor = pageAccessor; + _windowManager = windowManager; _keyboardMapper = keyboardMapper; } @@ -57,7 +58,7 @@ public virtual Task DisplayAlertAsync(string title, string message, string /// true if non-destructive button pressed; otherwise false/> public virtual Task DisplayAlertAsync(string title, string message, string acceptButton, string cancelButton, FlowDirection flowDirection) { - return _pageAccessor.Page.DisplayAlert(title, message, acceptButton, cancelButton, (MauiFlow)flowDirection); + return GetPage().DisplayAlert(title, message, acceptButton, cancelButton, (MauiFlow)flowDirection); } /// @@ -72,7 +73,7 @@ public virtual Task DisplayAlertAsync(string title, string message, string /// public virtual Task DisplayAlertAsync(string title, string message, string cancelButton) { - return _pageAccessor.Page.DisplayAlert(title, message, cancelButton); + return GetPage().DisplayAlert(title, message, cancelButton); } /// @@ -88,7 +89,7 @@ public virtual Task DisplayAlertAsync(string title, string message, string cance /// public virtual Task DisplayAlertAsync(string title, string message, string cancelButton, FlowDirection flowDirection) { - return _pageAccessor.Page.DisplayAlert(title, message, cancelButton, (MauiFlow)flowDirection); + return GetPage().DisplayAlert(title, message, cancelButton, (MauiFlow)flowDirection); } /// @@ -115,7 +116,7 @@ public virtual Task DisplayActionSheetAsync(string title, string cancelB /// Text for the pressed button public virtual Task DisplayActionSheetAsync(string title, string cancelButton, string destroyButton, FlowDirection flowDirection, params string[] otherButtons) { - return _pageAccessor.Page.DisplayActionSheet(title, cancelButton, destroyButton, (MauiFlow)flowDirection, otherButtons); + return GetPage().DisplayActionSheet(title, cancelButton, destroyButton, (MauiFlow)flowDirection, otherButtons); } /// @@ -177,6 +178,8 @@ public virtual async Task DisplayActionSheetAsync(string title, FlowDirection fl public virtual Task DisplayPromptAsync(string title, string message, string accept = "OK", string cancel = "Cancel", string placeholder = default, int maxLength = -1, KeyboardType keyboardType = KeyboardType.Default, string initialValue = "") { var keyboard = _keyboardMapper.Map(keyboardType); - return _pageAccessor.Page.DisplayPromptAsync(title, message, accept, cancel, placeholder, maxLength, keyboard, initialValue); + return GetPage().DisplayPromptAsync(title, message, accept, cancel, placeholder, maxLength, keyboard, initialValue); } + + private Page GetPage() => _windowManager.Windows.OfType().First().CurrentPage; }