Skip to content

Commit

Permalink
Merge pull request #2980 from PrismLibrary/dev/ds/dialog-xaml-root
Browse files Browse the repository at this point in the history
  • Loading branch information
dansiegel authored Oct 11, 2023
2 parents 17b9843 + d2c42f4 commit 91ee9b0
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
25 changes: 18 additions & 7 deletions src/Uno/Prism.Uno/Dialogs/DialogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(KnownDialogParameters.WindowName, out var wName) ? wName : null;
try
{
parameters ??= new DialogParameters();
var windowName = parameters.TryGetValue<string>(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<ContentDialogPlacement>(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)
Expand Down
3 changes: 2 additions & 1 deletion src/Uno/Prism.Uno/Dialogs/DialogWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ namespace Prism.Dialogs
/// </summary>
public partial class DialogWindow : ContentDialog, IDialogWindow
{
public DialogWindow()
public DialogWindow(Window window)
{
this.InitializeComponent();
XamlRoot = window.Content.XamlRoot;
}
public IDialogResult? Result { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion src/Uno/Prism.Uno/Dialogs/IDialogWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public interface IDialogWindow

object? Content { get; set; }

IAsyncOperation<ContentDialogResult> ShowAsync();
IAsyncOperation<ContentDialogResult> ShowAsync(ContentDialogPlacement placement);

void Hide();
}
Expand Down
1 change: 1 addition & 0 deletions src/Uno/Prism.Uno/PrismApplicationBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 6 additions & 1 deletion src/Wpf/Prism.Wpf/Dialogs/KnownDialogParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ public static class KnownDialogParameters
/// </summary>
public const string WindowName = "windowName";

#if !HAS_WINUI
#if HAS_WINUI
/// <summary>
/// The <see cref="Microsoft.UI.Xaml.Controls.ContentDialogPlacement"/> to use when showing the dialog
/// </summary>
public const string DialogPlacement = "dialogPlacement";
#else
/// <summary>
/// Flag to show the Dialog Modally or Non-Modally
/// </summary>
Expand Down

0 comments on commit 91ee9b0

Please sign in to comment.