I do not know your exact scenario, but I might be able to provide some ideas for this. If you are obtaining your MemberView’s
ViewModel reference used to call this method:
private void ListMember_SelectionChanged(object sender, SelectionChangedEventArgs e)
public static MemberViewModel Instance
if (instance == null)
instance = new MemberViewModel(new EventAggregator());
You are getting
a new instance of the EventAggregator service (which might not be a good idea since services are usually singletons, so you should be sure that a new instance is required by your application). When you fire
the event with that EventAggregator, there are no events subscribed. Something similar could be happening with the
ContractView. When publishing/subscribing events, you should make sure that you are using the same instance of the
EventAggregator service that is registered in the container.
You can achieve this in two different ways (that I can currently think of).
Use the ServiceLocator to get the EventAggregator singleton instance
Add a reference to the Microsoft.Practices.ServiceLocationAssembly. It is located in the
Modify the line that creates a new instance of each of your view models for the following:
instance = new ContratViewModel(ServiceLocator.Current.GetService(typeof(IEventAggregator))
Register your ViewModels as a singleton in the container
Register your ViewModel as a singleton in the UnityContainer. You can check
this article for information on how to achieve this.
In your views, you can resolve your singleton ViewModel through Unity’s resolve method.
ViewModel vm = container.Resolve<ViewModel>();
You can check the following article from the documentation which might provide more insight:
You can also check out some of the following solutions that come with the Guidance, which use
Event Aggregation QuickStart
Stock Trader Reference Implementation
Please let me know if this helps.