How to create a modal dialog with MVVM highlighting

What is the correct way to open a modal dialog in WPF using the latest MVVM Light framework. I also want to be able to pass values ​​to the ViewModel of the window used as a modal dialog.

I can't find any samples on the MVVM Light site.

+3


source to share


1 answer


You should use a DialogService, which abstracts the visual representation of the view so that you can "show" in the view model (and hopefully later on) mock it for testing.

Read more about DialogService here .



-edit- I was wrong as Alan Rutter (OP) points out that IDialogService is for simple message boxes only. I don't think the MVVM light will help you much here, but you can create a similar service (like ICustomDialogService?). Custom dialogs can be registered as available with a service, and then the interface provides calls that will allow you to invoke a specific dialog by name (perhaps String or Enum) and pass whatever parameters you want.

Dialogs can be registered with the service in several ways - this can happen for a type in static constructors (which you somehow need to enforce) or more explicitly through attributes in assemblies. It is even possible to use class attributes. It depends on your startup sequence and overall infrastructure.

0


source







All Articles