Skip to content

Commit 75e5da3

Browse files
authored
Merge pull request #3304 from PrismLibrary/wpf-dialog-fix
added window name to ShowDialog extension
2 parents bf70150 + c62666e commit 75e5da3

File tree

2 files changed

+39
-26
lines changed

2 files changed

+39
-26
lines changed
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Prism.Dialogs;
1+
using Prism.Dialogs;
22
using System;
33

44
namespace HelloWorld.Core
@@ -7,17 +7,22 @@ public static class DialogServiceExtensions
77
{
88
public static void ShowNotification(this IDialogService dialogService, string message, Action<IDialogResult> callBack)
99
{
10-
dialogService.ShowDialog("NotificationDialog", new DialogParameters($"message={message}"), callBack);
10+
dialogService.Show("NotificationDialog", new DialogParameters($"message={message}"), callBack);
11+
}
12+
13+
public static void ShowNotificationInAnotherWindow(this IDialogService dialogService, string message, Action<IDialogResult> callBack)
14+
{
15+
dialogService.Show("NotificationDialog", new DialogParameters($"message={message}"), callBack, "AnotherDialogWindow");
1116
}
1217

1318
public static void ShowConfirmation(this IDialogService dialogService, string message, Action<IDialogResult> callBack)
1419
{
1520
dialogService.ShowDialog("ConfirmationDialog", new DialogParameters($"message={message}"), callBack);
1621
}
1722

18-
public static void ShowNotificationInAnotherWindow(this IDialogService dialogService, string message, Action<IDialogResult> callBack)
23+
public static void ShowConfirmationInAnotherWindow(this IDialogService dialogService, string message, Action<IDialogResult> callBack)
1924
{
20-
dialogService.ShowDialog("NotificationDialog", new DialogParameters($"message={message}"), callBack, "AnotherDialogWindow");
25+
dialogService.ShowDialog("ConfirmationDialog", new DialogParameters($"message={message}"), callBack, "AnotherDialogWindow");
2126
}
2227
}
2328
}

src/Wpf/Prism.Wpf/Dialogs/IDialogServiceCompatExtensions.cs

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,20 @@ public static class IDialogServiceCompatExtensions
1111
/// </summary>
1212
/// <param name="dialogService">The DialogService</param>
1313
/// <param name="name">The name of the dialog to show.</param>
14-
/// <param name="parameters">The parameters to pass to the dialog.</param>
14+
public static void Show(this IDialogService dialogService, string name)
15+
{
16+
Show(dialogService, name, null, null, null);
17+
}
18+
19+
/// <summary>
20+
/// Shows a non-modal dialog.
21+
/// </summary>
22+
/// <param name="dialogService">The DialogService</param>
23+
/// <param name="name">The name of the dialog to show.</param>
1524
/// <param name="callback">The action to perform when the dialog is closed.</param>
16-
public static void Show(this IDialogService dialogService, string name, IDialogParameters parameters, Action<IDialogResult> callback)
25+
public static void Show(this IDialogService dialogService, string name, Action<IDialogResult> callback)
1726
{
18-
parameters = EnsureShowNonModalParameter(parameters);
19-
dialogService.ShowDialog(name, parameters, new DialogCallback().OnClose(callback));
27+
Show(dialogService, name, null, callback, null);
2028
}
2129

2230
/// <summary>
@@ -26,48 +34,48 @@ public static void Show(this IDialogService dialogService, string name, IDialogP
2634
/// <param name="name">The name of the dialog to show.</param>
2735
/// <param name="parameters">The parameters to pass to the dialog.</param>
2836
/// <param name="callback">The action to perform when the dialog is closed.</param>
29-
/// <param name="windowName">The name of the hosting window registered with the IContainerRegistry.</param>
30-
public static void Show(this IDialogService dialogService, string name, IDialogParameters parameters, Action<IDialogResult> callback, string windowName)
37+
public static void Show(this IDialogService dialogService, string name, IDialogParameters parameters, Action<IDialogResult> callback)
3138
{
32-
parameters = EnsureShowNonModalParameter(parameters);
33-
34-
if(!string.IsNullOrEmpty(windowName))
35-
parameters.Add(KnownDialogParameters.WindowName, windowName);
36-
37-
dialogService.ShowDialog(name, parameters, new DialogCallback().OnClose(callback));
39+
Show(dialogService, name, parameters, callback, null);
3840
}
3941

4042
/// <summary>
4143
/// Shows a non-modal dialog.
4244
/// </summary>
4345
/// <param name="dialogService">The DialogService</param>
4446
/// <param name="name">The name of the dialog to show.</param>
45-
public static void Show(this IDialogService dialogService, string name)
47+
/// <param name="parameters">The parameters to pass to the dialog.</param>
48+
/// <param name="callback">The action to perform when the dialog is closed.</param>
49+
/// <param name="windowName">The name of the hosting window registered with the IContainerRegistry.</param>
50+
public static void Show(this IDialogService dialogService, string name, IDialogParameters parameters, Action<IDialogResult> callback, string windowName)
4651
{
47-
var parameters = EnsureShowNonModalParameter(null);
48-
dialogService.Show(name, parameters, null);
52+
ShowDialogInternal(dialogService, name, parameters, callback, windowName, true);
4953
}
5054

5155
/// <summary>
52-
/// Shows a non-modal dialog.
56+
/// Shows a modal dialog.
5357
/// </summary>
5458
/// <param name="dialogService">The DialogService</param>
5559
/// <param name="name">The name of the dialog to show.</param>
60+
/// <param name="parameters">The parameters to pass to the dialog.</param>
5661
/// <param name="callback">The action to perform when the dialog is closed.</param>
57-
public static void Show(this IDialogService dialogService, string name, Action<IDialogResult> callback)
62+
/// <param name="windowName">The name of the hosting window registered with the IContainerRegistry.</param>
63+
public static void ShowDialog(this IDialogService dialogService, string name, IDialogParameters parameters, Action<IDialogResult> callback, string windowName)
5864
{
59-
var parameters = EnsureShowNonModalParameter(null);
60-
dialogService.Show(name, parameters, callback);
65+
ShowDialogInternal(dialogService, name, parameters, callback, windowName, false);
6166
}
6267

63-
private static IDialogParameters EnsureShowNonModalParameter(IDialogParameters parameters)
68+
private static void ShowDialogInternal(IDialogService dialogService, string name, IDialogParameters parameters, Action<IDialogResult> callback, string windowName, bool isNonModal)
6469
{
6570
parameters ??= new DialogParameters();
6671

67-
if (!parameters.ContainsKey(KnownDialogParameters.ShowNonModal))
72+
if (!string.IsNullOrEmpty(windowName))
73+
parameters.Add(KnownDialogParameters.WindowName, windowName);
74+
75+
if (isNonModal)
6876
parameters.Add(KnownDialogParameters.ShowNonModal, true);
6977

70-
return parameters;
78+
dialogService.ShowDialog(name, parameters, new DialogCallback().OnClose(callback));
7179
}
7280
#endif
7381
}

0 commit comments

Comments
 (0)