Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing multiple parameters to Prism's EventAggregator
    primarykey
    data
    text
    <p>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 <strong>ViewModelA</strong> which need to update properties in <strong>ViewModelB</strong> when their values change. My current solution involves:</p> <p><strong>ViewModelA</strong> publishes an Event with the new value for FirstName as the payload:</p> <pre><code> public string FirstName { get {return firstName;} set { this.firstName = value; eventAggregator.GetEvent&lt;PatientDetailsEvent&gt;().Publish(firstName); } } </code></pre> <p><strong>ViewModelB</strong> is subscribed to the Event and changes its FirstName property accordingly:</p> <pre><code>public PatientBannerViewModel(IEventAggregator eventAggregator) { this.eventAggregator = eventAggregator; eventAggregator.GetEvent&lt;PatientDetailsEvent&gt;().Subscribe(UpdateBanner, ThreadOption.UIThread); } public void UpdateBanner(string firstName) { this.FirstName = firstName; } </code></pre> <p>This works fine for a single property. It doesn't work for multiple, different properties because <strong>ViewModelB</strong> has no idea what property has changed on <strong>ViewModelA</strong> . ViewModelB knows what the new value is, but it doesn't know which of its properties to update. </p> <p>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? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload