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

added window name to ShowDialog extension #3304

Merged
merged 1 commit into from
Jan 26, 2025
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
13 changes: 9 additions & 4 deletions e2e/Wpf/HelloWorld.Core/DialogServiceExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Prism.Dialogs;
using Prism.Dialogs;
using System;

namespace HelloWorld.Core
Expand All @@ -7,17 +7,22 @@ public static class DialogServiceExtensions
{
public static void ShowNotification(this IDialogService dialogService, string message, Action<IDialogResult> callBack)
{
dialogService.ShowDialog("NotificationDialog", new DialogParameters($"message={message}"), callBack);
dialogService.Show("NotificationDialog", new DialogParameters($"message={message}"), callBack);
}

public static void ShowNotificationInAnotherWindow(this IDialogService dialogService, string message, Action<IDialogResult> callBack)
{
dialogService.Show("NotificationDialog", new DialogParameters($"message={message}"), callBack, "AnotherDialogWindow");
}

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

public static void ShowNotificationInAnotherWindow(this IDialogService dialogService, string message, Action<IDialogResult> callBack)
public static void ShowConfirmationInAnotherWindow(this IDialogService dialogService, string message, Action<IDialogResult> callBack)
{
dialogService.ShowDialog("NotificationDialog", new DialogParameters($"message={message}"), callBack, "AnotherDialogWindow");
dialogService.ShowDialog("ConfirmationDialog", new DialogParameters($"message={message}"), callBack, "AnotherDialogWindow");
}
}
}
52 changes: 30 additions & 22 deletions src/Wpf/Prism.Wpf/Dialogs/IDialogServiceCompatExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@ public static class IDialogServiceCompatExtensions
/// </summary>
/// <param name="dialogService">The DialogService</param>
/// <param name="name">The name of the dialog to show.</param>
/// <param name="parameters">The parameters to pass to the dialog.</param>
public static void Show(this IDialogService dialogService, string name)
{
Show(dialogService, name, null, null, null);
}

/// <summary>
/// Shows a non-modal dialog.
/// </summary>
/// <param name="dialogService">The DialogService</param>
/// <param name="name">The name of the dialog to show.</param>
/// <param name="callback">The action to perform when the dialog is closed.</param>
public static void Show(this IDialogService dialogService, string name, IDialogParameters parameters, Action<IDialogResult> callback)
public static void Show(this IDialogService dialogService, string name, Action<IDialogResult> callback)
{
parameters = EnsureShowNonModalParameter(parameters);
dialogService.ShowDialog(name, parameters, new DialogCallback().OnClose(callback));
Show(dialogService, name, null, callback, null);
}

/// <summary>
Expand All @@ -26,48 +34,48 @@ public static void Show(this IDialogService dialogService, string name, IDialogP
/// <param name="name">The name of the dialog to show.</param>
/// <param name="parameters">The parameters to pass to the dialog.</param>
/// <param name="callback">The action to perform when the dialog is closed.</param>
/// <param name="windowName">The name of the hosting window registered with the IContainerRegistry.</param>
public static void Show(this IDialogService dialogService, string name, IDialogParameters parameters, Action<IDialogResult> callback, string windowName)
public static void Show(this IDialogService dialogService, string name, IDialogParameters parameters, Action<IDialogResult> callback)
{
parameters = EnsureShowNonModalParameter(parameters);

if(!string.IsNullOrEmpty(windowName))
parameters.Add(KnownDialogParameters.WindowName, windowName);

dialogService.ShowDialog(name, parameters, new DialogCallback().OnClose(callback));
Show(dialogService, name, parameters, callback, null);
}

/// <summary>
/// Shows a non-modal dialog.
/// </summary>
/// <param name="dialogService">The DialogService</param>
/// <param name="name">The name of the dialog to show.</param>
public static void Show(this IDialogService dialogService, string name)
/// <param name="parameters">The parameters to pass to the dialog.</param>
/// <param name="callback">The action to perform when the dialog is closed.</param>
/// <param name="windowName">The name of the hosting window registered with the IContainerRegistry.</param>
public static void Show(this IDialogService dialogService, string name, IDialogParameters parameters, Action<IDialogResult> callback, string windowName)
{
var parameters = EnsureShowNonModalParameter(null);
dialogService.Show(name, parameters, null);
ShowDialogInternal(dialogService, name, parameters, callback, windowName, true);
}

/// <summary>
/// Shows a non-modal dialog.
/// Shows a modal dialog.
/// </summary>
/// <param name="dialogService">The DialogService</param>
/// <param name="name">The name of the dialog to show.</param>
/// <param name="parameters">The parameters to pass to the dialog.</param>
/// <param name="callback">The action to perform when the dialog is closed.</param>
public static void Show(this IDialogService dialogService, string name, Action<IDialogResult> callback)
/// <param name="windowName">The name of the hosting window registered with the IContainerRegistry.</param>
public static void ShowDialog(this IDialogService dialogService, string name, IDialogParameters parameters, Action<IDialogResult> callback, string windowName)
{
var parameters = EnsureShowNonModalParameter(null);
dialogService.Show(name, parameters, callback);
ShowDialogInternal(dialogService, name, parameters, callback, windowName, false);
}

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

if (!parameters.ContainsKey(KnownDialogParameters.ShowNonModal))
if (!string.IsNullOrEmpty(windowName))
parameters.Add(KnownDialogParameters.WindowName, windowName);

if (isNonModal)
parameters.Add(KnownDialogParameters.ShowNonModal, true);

return parameters;
dialogService.ShowDialog(name, parameters, new DialogCallback().OnClose(callback));
}
#endif
}
Expand Down
Loading