3
votes

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

I cannot find any samples on the MVVM Light site.

1

1 Answers

0
votes

You should use the DialogService which abstracts the visual representation of the view so that you can do "Show" within the view model (and later possibly/hopefully) mock it for testing.

More info on the DialogService here.

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

Dialogs can register with the service in a few different ways - can happen for the type in static constructors (that you somehow have to force) or more explicitly through attributes in assemblies. Possibly even using class attributes. It depends on your startup sequence and general infrastructure.