I am trying to create a WPF application by using WPF and PRISM. I am also using MEF and mvvm. Is it possible to have 2 viewmodels that can communicate to each other by using the event aggregastor? Eg. Publish in viewmodel A and subscribe in Viewmodel B? And if so how? I have build a program with multiple viewmodels and some of these viewmodels should communicate with each other, but somehow if I publish in Viewmodel A using a eventaggregator, A subscribe in viewmodel B will never be recognized to belong to the same eventaggregator so that I cannot update my View connected to viewmodel B.
0
votes
5 Answers
1
votes
This is the basic key steps to define Event Aggregator
(1) Create Event Agg..
public class YourEvent: CompositePresentationEvent {
}
(2) Publisher vm
eventAggregator.Get().Publish(object);
(3) Subscription Vm
YourEvent eventobj = eventAggregator.Get();
if (subscriptionToken != null)
{
eventobj.Unsubscribe(subscriptionToken);
}
subscriptionToken = eventobj.Subscribe(YourEventHandler, ThreadOption.UIThread, false, yourfun);
0
votes
0
votes
0
votes