Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DialogService - Setting XamlRoot #2980

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading