MVVM Light offers a class specific to every ViewModel instance that is used in the context of an application - Messenger. One might ask - what exactly is it and why it is needed? The answer is simple - in a more complex application, ViewModel instances are not standalone entities. Chances are you would like to pass specific data from one model to another, and Messenger is facilitating this process.
Let's look at specific source code to illustrate its activity. Initially, I have a standard test view model (named TestViewModel):
public class TestViewModel : ViewModelBase
{
public TestViewModel()
{
}
private string tS = "tS";
public string TestString
{
get
{
return tS;
}
set
{
tS = value;
RaisePropertyChanged("TestString");
}
}
}
Nothing super useful here - just a dummy string property with an associated field that has a default value. Let's say I have another ViewModel instance that contains additional data (not necessarily related to the ViewModel above):
public class MainViewModel : ViewModelBase
{
public MainViewModel()
{
}
private string pA = "pA";
public string PropertyA
{
get
{
return pA;
}
set
{
RaisePropertyChanged("PropertyA");
}
}
}
Read more: Windows Phone 7