This project is read-only.

Any examples to display Dialogs with MVVM Foundation?

Oct 12, 2010 at 10:29 AM

I know that I am supposed to use Messenger/MVVM Mediator pattern for this, but I don't quite understand the workings/structure of how I can implement that. Are there any examples that will help?

Feb 28, 2013 at 5:52 PM
How did you solve this situation? It´s a typical scenario, but I still didn't figure it out. Thanks in advance.
May 10, 2013 at 7:34 PM
Edited May 10, 2013 at 7:48 PM
Here is an example that I have used. In this example I am using MVVM Foundation Messenger to show a different view.

You will have to do the following in a ViewModel where you want to send the message from. In my example, I am sending a message and passing a parameter (name of another View - it can be any object)
 Mediator.NotifyColleagues<string>(MediatorMessages.ShowInterface, "BidQueryResultInterface");
Mediator.NotifyColleagues is a Messenger method that notifies all registered ViewModels (this will be covered shortly). MediatorMessages.ShowInterface is just a class and a string constant that I use for passing the messages around. Much easier then typing the name every time. The example of this class is below:
public static class MediatorMessages
    public const string ShowInterface = "ShowInterface";
Now on to the receiving end. In another ViewModel we have to register the method that will be receiving these messages. Note that in the constructor of your ViewModel you need to register the Messenger:
You decorate the method that will receive the messages as shown below. The definition of this would match the Message you are sending. I am showing the one that matches the example I used:
[MediatorMessageSink(MediatorMessages.ShowInterface, ParameterType = typeof(string))]
private void ShowInterface(string interfaceType)
    //The code to handle the Message goes here
For my purposes to show the Dialog I stored the interfaceType into a Parameter (InterfaceName) to which my ShellView is binded to. In the ShellView I use DataTemplates to decide which DialogView to show (based on the InterfaceName). For each Dialog that the application would show I have the appropriate View and ViewModel. The responses from the Dialog are routed back to the ViewModel that sent the message. Unfortunately I do not currently have an example for this last part, but if you are having issues figuring things out, I could whip one up.

Hope this helped! Feel free to reply back if you have any questions, I'll try and help if I can.