I think you should use a reseller template which you can read here .
This is basically a static class that allows ViewModels (or any class, for that matter) to interact with each other and pass arguments back and forth.
Basically, ViewModel A starts listening to a specific type of message (e.g. ViewModelBChanged), and whenever this event occurs, ViewModelB just notifies everyone who listens to this type of message, it can also transmit any information it wants.
Here is the skeleton of the pick.
public static class MyMediator { public static void Register(Action<object> callback, string message); public static void NotifyColleagues(string message, object args); }
ViewModel A will do this (possibly in the constructor):
MyMediator.Register(ProcessMessage,"ViewModelBChanged")
and then you need to declare a function like this:
void ProcessMessage(object args) {
and ViewModel B will call this when it wants to tell ViewModel A
MyMediator.NotifyColleagues("ViewModelBChanged",this);
The mediation class will be responsible for calling the viewModel A callback function. And then everyone is happy.
Personally, I like to put these string values in a static class, like this
static class MediatorMessages { public static string ViewModelBChanged= "ViewModelBChanged"; }
So that you can do the following (instead of the above):
MyMediator.Register(ProcessMessage,MediatorMessages.ViewModelBChanged) MyMediator.NotifyColleagues(MediatorMessages.ViewModelBChanged,this);
If this is unclear, just google MVVM broker and click on your content :)