简体   繁体   中英

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. We are using MVVM architecture pattern along with PRISM framework. We have used Telerik control to make rich UI for application.

We have Developed the Modular application in PRISM as shown in Prism Sample For WPF-07 Applications . In this we are having one main application will be having Bootstrapper class and reference of all the submodules.

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.

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 .

But this functionality no more exist in new Prism version. Also Sample application is not present for the new functionality of Dialog Service on 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?

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.

This works for public MyViewModel( IDialogService dialogService ) {... } no matter where the code of MyViewModel resides, as long as it's called by the container. 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).

All this works in exactly the same way for view models defined in the main app and those defined in modules.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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