Reputation: 1381
I am trying to learn to use the MVVM Light Toolkit but i did not find a concrete definition of what is
"Messaging"
and the
"Messenger Class"
mvvm light - messaging Someone asked this question but before reading the articles that are given in the answers can anyone give a concrete definition of what Messaging means in MVVM ? Thank you !
Upvotes: 0
Views: 115
Reputation: 355
There are some cases wich is not easy to make a property in the viewmodel and link it to the view. You need a class to bind any property from the code behind the WPF to the viewmodel.
In the following example, every time the user selects several rows from the grid (the view), the number of selected rows is passed to the viewmodel using the Messenger class:
//in the view
public MainWindow(){
InitializeComponent();
this.MyGrid.SelectionChanged += MyGrid_SelectionChanged;
}
void MyGrid_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
Messenger.Default.Send<IList>(this.MyGrid.SelectedItems);
}
//in the viewmodel
private IList _numFilasSeleccionadas;
public IList NumFilasSeleccionadas
{
get { return _numFilasSeleccionadas; }
set
{
_numFilasSeleccionadas = value;
RaisePropertyChanged("NumFilasSeleccionadas");
}
}
private void RegisterCommands()
{
Messenger.Default.Register<IList>(this, d => this.NumFilasSeleccionadas = d);
}
Upvotes: 1