Quantcast
Channel: patterns & practices: Prism
Viewing all articles
Browse latest Browse all 1878

New Post: Communicating between views in multitab application

$
0
0
Hi,

As a possible option to do this, you could provide the ID by raising an event through EventAggregator, so Filter and Result view models can get this ID assigned like this:

  • Subscribe to the event on both Filter and Result view models constructor and store the ID provided
public FilterViewModel(IEventAggregator eventAggregator, ....)
{
     //do thingsthis.eventAggregator = eventAggregator;
     this.eventAggregator.GetEvent<ProvideIDEvent>().Subscribe(StoreID);
}

privatevoid StoreID(string ID)
{
     this.FilterID = ID;
     this.eventAggregator.GetEvent<ProvideIDEvent>().Unsubscribe(StoreID);
}
  • In your code behind from SearchView, set your DataContext to get your SearchViewModel from ServiceLocator. This must be done after the call to InitializeComponent so Filter and Result view models will be initialized before the SearchViewModel
public SearchView()
{
     InitializeComponent();
     this.DataContext = this.ServiceLocator.Current.GetInstance<SearchViewModel>();
}
  • Then, in your SearchViewModel, at the end of your constructor, raise the event that will provide the ID to Filter and Result view models. This ID will be used then in Filter and Result view models to identify between them and know which of the Result views should be updated.
public SearchViewModel(IEventAggregator eventAggregator, ....)
{
     //do thingsthis.eventAggregator.GetEvent<ProvideIDEvent>().Publish(ID);
}
This way, each time you open a new Search tab, both Filter and Result views related to this tab will be assigned with a unique ID so you can use subscription filtering to determine which Result view should be updated.

Hope this helps,

Federico Martinez
http://blogs.southworks.net/fmartinez

Viewing all articles
Browse latest Browse all 1878

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>