I have a ShellWindow which has a IEventAggregator and all my child publish to this IEventAggregator?.
Now i have a static class named JIMSMessage in which i publish to IEventAggregator of ShellViewModel.
public static class JIMSMessage
{
public static bool Show(IEventAggregator _events, string message)
{
_events.Publish(new Message()
{
MessageValue = message
});
return true;
}
}
I want my return value of Show method to come from the ViewModel, which calls this method..
Lets say…
I have a ViewModel named LedgerViewModel, this calls the JIMSMessage.Show as follows,
JIMSMessage.Show(_events,"Enter Ledger Name.");
Its working, but my MessageWindowViewModel returns something, which i want to return to JIMSMessage class, how can i do this. Please help me.
I don’t think the
EventAggregatoris really meant to work that way. It is used to Publish events for anyone who cares to receive those events, or to Subscribe to events if something is interested in being alerted about an event.It is not meant to be used to make a call and wait for a return value within the same method.
What you could do instead is publish something like a
ShowMessageevent, and subscribe to receive aMessageShownevent.For example, your
ShellViewModelmight subscribe to receive MessageDisplayed event messages and handle them like this:and elsewhere in your application you could publish a ShowMessage event to display a message
And whatever class is responsible for displaying messages would subscribe to receive
ShowMessageEvent, show the message, wait for user feedback, then broadcast aMessageDisplayedevent with the results when its finished.Also if you’re interested, I wrote a Static class for the EventAggregator that makes dealing with PRISM’s
EventAggregatormuch simpler. You might be interested in checking it out.