Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple parameters with CompositePresentationEvent<> in Prism

Tags:

c#

events

prism

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?

like image 664
mersadk Avatar asked Dec 05 '25 11:12

mersadk


1 Answers

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 */ } });
like image 73
Bahri Gungor Avatar answered Dec 07 '25 00:12

Bahri Gungor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!