I would like to know how to pass two or more parameters to Prism event aggregator (event class inherits CompositePresentationEvent)?
I know I can create wrapper class like EventArgs and create property for each value I need, but I would rather to pass two distinct parameters.
Is this possible?
Unfortunately, the event aggregator is only set up to pass a single parameter. HOWEVER, that parameter can be a class or structure.
Here is an example of a "message" I pass with event aggregator, including a callback parameter.
public class OpenViewPayload
{
public string ViewName;
public object Context;
public Action callback;
}
[Export]
[PartCreationPolicy(CreationPolicy.Shared)]
public class OpenViewEvent : CompositePresentationEvent<OpenViewPayload>
{
}
Usage:
_eventAggregator.GetEvent<OpenViewEvent>().Publish(new OpenViewPayload() { ViewName = "CustomerView", Context = _selectedCustomerID, callback= ()=> { /* Close Current View */ } });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With