diff --git a/src/Uno/Prism.Uno/Dialogs/DialogService.cs b/src/Uno/Prism.Uno/Dialogs/DialogService.cs index 55c0d03067..67e159b98c 100644 --- a/src/Uno/Prism.Uno/Dialogs/DialogService.cs +++ b/src/Uno/Prism.Uno/Dialogs/DialogService.cs @@ -16,16 +16,27 @@ public DialogService(IContainerProvider containerProvider) _containerProvider = containerProvider; } - public void ShowDialog(string name, IDialogParameters parameters, DialogCallback callback) + public async void ShowDialog(string name, IDialogParameters parameters, DialogCallback callback) { - parameters ??= new DialogParameters(); - var windowName = parameters.TryGetValue(KnownDialogParameters.WindowName, out var wName) ? wName : null; + try + { + parameters ??= new DialogParameters(); + var windowName = parameters.TryGetValue(KnownDialogParameters.WindowName, out var wName) ? wName : null; + + IDialogWindow contentDialog = CreateDialogWindow(windowName); + ConfigureDialogWindowEvents(contentDialog, callback); + ConfigureDialogWindowContent(name, contentDialog, parameters); - IDialogWindow contentDialog = CreateDialogWindow(windowName); - ConfigureDialogWindowEvents(contentDialog, callback); - ConfigureDialogWindowContent(name, contentDialog, parameters); + var placement = parameters.ContainsKey(KnownDialogParameters.DialogPlacement) ? + (parameters[KnownDialogParameters.DialogPlacement] is ContentDialogPlacement placementValue ? placementValue : Enum.Parse(parameters[KnownDialogParameters.DialogPlacement].ToString() ?? string.Empty)) : ContentDialogPlacement.Popup; - _ = contentDialog.ShowAsync(); + await contentDialog.ShowAsync(placement); + } + catch (Exception ex) + { + var str = ex.ToString(); + await callback.Invoke(ex); + } } IDialogWindow CreateDialogWindow(string? name) diff --git a/src/Uno/Prism.Uno/Dialogs/DialogWindow.xaml.cs b/src/Uno/Prism.Uno/Dialogs/DialogWindow.xaml.cs index 938b3c9e3f..f4720965ee 100644 --- a/src/Uno/Prism.Uno/Dialogs/DialogWindow.xaml.cs +++ b/src/Uno/Prism.Uno/Dialogs/DialogWindow.xaml.cs @@ -10,9 +10,10 @@ namespace Prism.Dialogs /// public partial class DialogWindow : ContentDialog, IDialogWindow { - public DialogWindow() + public DialogWindow(Window window) { this.InitializeComponent(); + XamlRoot = window.Content.XamlRoot; } public IDialogResult? Result { get; set; } diff --git a/src/Uno/Prism.Uno/Dialogs/IDialogWindow.cs b/src/Uno/Prism.Uno/Dialogs/IDialogWindow.cs index 8ca332338b..a6bc493624 100644 --- a/src/Uno/Prism.Uno/Dialogs/IDialogWindow.cs +++ b/src/Uno/Prism.Uno/Dialogs/IDialogWindow.cs @@ -20,7 +20,7 @@ public interface IDialogWindow object? Content { get; set; } - IAsyncOperation ShowAsync(); + IAsyncOperation ShowAsync(ContentDialogPlacement placement); void Hide(); } diff --git a/src/Uno/Prism.Uno/PrismApplicationBase.cs b/src/Uno/Prism.Uno/PrismApplicationBase.cs index 95a1a9af4b..3e6951dbef 100644 --- a/src/Uno/Prism.Uno/PrismApplicationBase.cs +++ b/src/Uno/Prism.Uno/PrismApplicationBase.cs @@ -109,6 +109,7 @@ protected virtual void Initialize(IApplicationBuilder builder) .Configure(x => x.ConfigureServices(ConfigureServices) .UseServiceProviderFactory(new PrismServiceProviderFactory(_containerExtension))); + _containerExtension.RegisterInstance(builder.Window); RegisterRequiredTypes(_containerExtension); RegisterTypes(_containerExtension); _containerExtension.FinalizeExtension(); diff --git a/src/Wpf/Prism.Wpf/Dialogs/KnownDialogParameters.cs b/src/Wpf/Prism.Wpf/Dialogs/KnownDialogParameters.cs index aef08f71d8..8d2231608c 100644 --- a/src/Wpf/Prism.Wpf/Dialogs/KnownDialogParameters.cs +++ b/src/Wpf/Prism.Wpf/Dialogs/KnownDialogParameters.cs @@ -10,7 +10,12 @@ public static class KnownDialogParameters /// public const string WindowName = "windowName"; -#if !HAS_WINUI +#if HAS_WINUI + /// + /// The to use when showing the dialog + /// + public const string DialogPlacement = "dialogPlacement"; +#else /// /// Flag to show the Dialog Modally or Non-Modally ///