I am writing my code in WPF where I have two view models. In one view model, I am closing a prism pop up window and on close I am calling my publishing method like:
Code
private void OnCancelInteraction() { _eventAggregator.GetEvent<PubSubEvent>().Publish(); this.FinishInteraction(); }while my subscribe event goes like this:
Code
public ResidentListViewModel(IResidentService residentService, IUserService userService, IEventAggregator eventAggregator) { var res = eventAggregator.GetEvent<PubSubEvent>().Subscribe(InitializeCollectionView); _residentService = residentService; _userService = userService; _eventAggregator = eventAggregator; InitializeCollectionView(); //***The InteractionRequest class FormDialogOpenRequest = new InteractionRequest<INotification>(); ConfirmationRequest = new InteractionRequest<IConfirmation>(); //*** Commands for each of the buttons RaiseFormDialogOpenCommand = new DelegateCommand<object>(this.RaiseFormDialogOpen); aiseConfirmationCommand = new DelegateCommand<object>(this.RaiseConfirmation); }Here is how both of these classes are receiving event aggregator:
Code
UnityContainer container = new UnityContainer(); var aggregator = container.Resolve<EventAggregator>(); this.DataContext = new ResidentFormDialogViewModel(residentService, userService, unitService, aggregator);here is my second class:
Code
UnityContainer container = new UnityContainer(); var aggregator = container.Resolve<EventAggregator>(); DataContext = new ResidentListViewModel(residentService, userService, aggregator);Every time I cancel my interaction, the publishing gets published but ResidentListViewModel is not being called as for subscribing.
ResidentListViewModel is being called before the other class which has subscribe method. Could it be a problem? All I want is to Initialize my collection view whenever the interaction gets finished without breaking the MVVM Pattern? If there is any other method please do suggest.
Answers
Know the answer? Post it. Somebody with the same question will find it here.