Let's say I have two models ViewModels and ViewModelLocator. I want to be able to pass parameters between all three without problems. How will I do this with the messenger? Is it capable?
What exactly, yes.
Send a message:
MessengerInstance.Send(payload, token);
To receive a message:
MessengerInstance.Register<PayloadType>( this, token, payload => SomeAction(payload));
There are many overloads, therefore, not knowing exactly what you are trying to do through the messenger, I will not go into all of them, but the above should cover a simple case when you want to send and receive a message with a payload.
Note that a token can really be anything that identifies a message. Although a string is often used for this, I prefer to use an enumeration because it is a little safer and allows intellisense, "find usages", etc.
For instance:
public enum MessengerToken { BrushChanged, WidthChanged, HeightChanged }
Then your transfer / receipt will look something like this:
// sending view model MessengerInstance.Send(Brushes.Red, MessengerToken.BrushChanged); // receiving view model // put this line in the constructor MessengerInstance.Register<Brush>(this, token, brush => ChangeColor(brush)); public void ChangeColor(Brush brush) { Brush = brush; }
[EDIT] The devuxer comment URL below is changed to: http://blog.galasoft.ch/posts/2009/09/mvvm-light-toolkit-messenger-v2/
source share