简体   繁体   English

从 WPF 呼叫消息警报 在 PRISM 模块化应用程序中查看 Model

[英]Call Message Alert from WPF View Model in PRISM Modular Application

We are new to Window application and we are developing a window application based on WPF.我们是 Window 应用程序的新手,我们正在开发基于 WPF 的 window 应用程序。 We are using MVVM architecture pattern along with PRISM framework.我们使用 MVVM 架构模式和 PRISM 框架。 We have used Telerik control to make rich UI for application.我们使用 Telerik 控件为应用程序制作了丰富的 UI。

We have Developed the Modular application in PRISM as shown in Prism Sample For WPF-07 Applications .我们在 PRISM 中开发了模块化应用程序,如WPF-07 应用程序的 Prism 示例所示。 In this we are having one main application will be having Bootstrapper class and reference of all the submodules.在此我们有一个主要应用程序将拥有引导程序 class 和所有子模块的参考。

We want to call alert box when certain operation perform by user is completed.当用户执行的某些操作完成时,我们想调用警报框。 We want to call this alert box from view model of many different pages, some are present in sub modules and few are present in Main application having bootstrapper.我们想从许多不同页面的 model 视图中调用此警报框,其中一些存在于子模块中,而少数存在于具有引导程序的主应用程序中。

We want to design common alert control which can be used across application.我们希望设计可以跨应用程序使用的通用警报控件。

In previously downloaded PRISM sample for WPF it was having codes sample for popup windows getting called from ViewModel as stated in this stack overflow question .在之前下载的 WPF 的 PRISM 示例中,它具有从 ViewModel 调用的弹出窗口 windows 的代码示例,如此堆栈溢出问题中所述。

But this functionality no more exist in new Prism version.但是这个功能在新的 Prism 版本中不再存在。 Also Sample application is not present for the new functionality of Dialog Service on Github.此外,Github 上对话服务的新功能不存在示例应用程序。

We know now 'Interaction' is replaced by DialogService and following the documentation we have created the custom alert in main application, but how can we use this alert in all the sub modules?我们现在知道 'Interaction' 被DialogService取代,并且按照文档我们在主应用程序中创建了自定义警报,但是我们如何在所有子模块中使用这个警报呢?

How can we design custom common alert accessible from all the modules?我们如何设计可从所有模块访问的自定义公共警报? Kindly help us to achieve this common functionality.请帮助我们实现这个通用功能。

how to call it from other modules?如何从其他模块调用它?

When a service (like the DialogService ) is registered with the container, it will be injected into all constructors that request it as dependency if those are resolved from the container.当服务(如DialogService )在容器中注册时,如果这些服务是从容器中解析的,它将被注入到所有请求它作为依赖项的构造函数中。

This works for public MyViewModel( IDialogService dialogService ) {... } no matter where the code of MyViewModel resides, as long as it's called by the container.这适用于public MyViewModel( IDialogService dialogService ) {... }无论MyViewModel的代码位于何处,只要它被容器调用。 No matter where it resides, the view model has to be linked to its view (by naming convention or explicit call) to be found by the view model locator (and thus created "magically" by the framework) or you have to resolve it yourself (eg by injecting a Func< MyViewModel> or a hand-coded factory or - do not do this - by injecting the container or - avoid this, too - by calling new and providing the dependencies yourself).无论它位于何处,视图 model 都必须链接到它的视图(通过命名约定或显式调用),才能由视图 model 定位器找到(因此由框架“神奇地”创建)或者您必须自己解决它(例如,通过注入Func< MyViewModel>或手动编码的工厂或 - 不要这样做 - 通过注入容器或 - 也避免这种情况 - 通过调用new并自己提供依赖项)。

All this works in exactly the same way for view models defined in the main app and those defined in modules.对于主应用程序中定义的视图模型和模块中定义的视图模型,所有这些都以完全相同的方式工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM