【问题标题】:Extending DialogService in Prism在 Prism 中扩展 DialogService
【发布时间】:2021-11-04 21:28:00
【问题描述】:

在 Prism 库网站上有一些关于简化应用程序对话框 API 的说明。 https://prismlibrary.com/docs/wpf/dialog-service.html

假设我有一个包含多个项目的解决方案,MainProject、Modules.Module1、CoreProject。所以在我的核心项目中创建这个DialogServiceExtensions 类。

public static class DialogServiceExtensions
{
    public static void ShowNotification(this IDialogService dialogService, string message, Action<IDialogResult> callBack)
    {
        dialogService.ShowDialog(nameof(NotificationDialog), new DialogParameters($"message={message}"), callBack, "notificationWindow");
    }
}

我还将NotificationDialogNotificationDialogViewModel 放在我的核心项目中

我可以在任何项目/模块中调用它,但问题是我如何告诉 prism NotificationDialog ViewModel 是 NotificationDialogViewModel

我应该在哪里注册对话框,以便能够通过孔解决方案使用?像往常一样在我的 MainProject App.xaml.cs 中?

protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.RegisterDialog<NotificationDialog, NotificationDialogViewModel>();
        }

【问题讨论】:

    标签: wpf mvvm dialog prism


    【解决方案1】:

    我应该在哪里注册对话框,以便能够通过孔解决方案使用?像往常一样在我的 MainProject App.xaml.cs 中?

    如果应用想要显示一个对话框,你必须这样做,因为模块本质上是可选的(它们可以在部署后被换出或者它们不需要存在)。

    如果一个模块想要显示一个对话框(而不是应用程序),您可以决定它是否是应用程序与其模块的接口的一部分(然后将注册放入应用程序中)或不(然后将其放入模块中,每个使用它的模块,即注册可能会相互覆盖)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-23
      • 2012-02-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多