Skip to content

ViewModel communication

Reflection Emit edited this page Dec 15, 2017 · 5 revisions

MessageManager

Some scenrios requires a ViewModel to be able to trigger or message other ViewModels to do something like updating. This can be done using the MessageManager. Sure, you can actually hard-wire your ViewModels, but if we are talking about windows, that does not know their instances, things can get messy very fast.
In order for the ViewModels to receive messages from the MessageManager, they have to subscribe. The sender itself do no need a subscription. Every message type requires its own argument type which derives from the MessagingArgs class. Only the viewmodels that subscribed to that specific messaging argument will receive a message.

ViewModel Children

Sometimes it is very impractical to use the MessageManager. One of these scenarios would be if you have a ViewModel with a collection, which could contain a lot of items that are able to change the parents IsLoading and IsChanged status. Cauldron offers a solution for this certain case: the RegisterChildrenAttribute.

[RegisterChildren]
public ObservableCollection<BankAccountViewModel> BankAccounts {get; private set;} = new ObservableCollection<BankAccountViewModel>();