Multiple instances of a module that publishes the same event

Topics: Prism v2 - WPF 3.5
Jan 31, 2009 at 12:19 AM
I have a module that displays an explorer treeview. I have 3 instances of the module in my window. I pubish a CompositeWpfEvent with a LocationItem class when an item is selected. How can a subscriber distinguish between the three?

I think I know the answer but I want to make sure there isn't another way. My guess is that I have to declare some sort of id on the LocationItem, when the instance of the module is created I have to set that id on the viewmodel and when the event is published I have to publish the LocationItem with the id from the viewmodel. My subscriber will have to filter on that item.
Feb 2, 2009 at 7:04 PM



You are right about you will need an ID in your LocationItem class to be able to filter the event before the registered handler is called. The filter could be supplied as a lambda expression, as shown in the following bold code:


FundAddedEvent fundAddedEvent = eventAggregator.GetEvent<FundAddedEvent>();

fundAddedEvent.Subscribe(FundAddedEventHandler, ThreadOption.UIThread, false, fundOrder => fundOrder.CustomerId == _customerId);




public void FundAddedEventHandler(FundOrder fundOrder)





Perhaps you could find useful the EventAggregation Quickstart. This sample application uses a filter expression to define a condition that the event's argument must meet for the event handler to be invoked.


Note: I assume that you are referring to 3 instances of a view that belongs to the same module, since the module is initialized only once.


Please let me know if this helps.


Mariano Converti