I'm using Prism's EventAggregator for loosely coupled communication between my module's ViewModels. I have have several properties (e.g. FirstName, LastName) in ViewModelA which need to update properties in ViewModelB when their values change. My current solution involves:
ViewModelA publishes an Event with the new value for FirstName as the payload:
public string FirstName
{
get {return firstName;}
set
{
this.firstName = value;
eventAggregator.GetEvent<PatientDetailsEvent>().Publish(firstName);
}
}
ViewModelB is subscribed to the Event and changes its FirstName property accordingly:
public PatientBannerViewModel(IEventAggregator eventAggregator)
{
this.eventAggregator = eventAggregator;
eventAggregator.GetEvent<PatientDetailsEvent>().Subscribe(UpdateBanner, ThreadOption.UIThread);
}
public void UpdateBanner(string firstName)
{
this.FirstName = firstName;
}
This works fine for a single property. It doesn't work for multiple, different properties because ViewModelB has no idea what property has changed on ViewModelA . ViewModelB knows what the new value is, but it doesn't know which of its properties to update.
I could create separate Events for each property but this seems repetitive. It seems cleaner to just use one Event. Ideally, when publishing the Event, ViewModelA should tell ViewModelB which property has changed. How can I do this?