Skip to content

Commit

Permalink
chore: catch exceptions to invoke for DialogResult
Browse files Browse the repository at this point in the history
  • Loading branch information
dansiegel committed Oct 11, 2023
1 parent df68b81 commit d2c42f4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 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
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 d2c42f4

Please sign in to comment.