Reputation: 68
I'm new to Prism so need some help on navigation between views In my project I have just 4 views, so I have created all view in one module. I have created shell and bootstrapper. What I need to do is, I need to pass some data from one view to another(for eg, First view has list of employees, I select one employee and I will click Button to get the details of that employee). Currently I'm using ViewModel first approach`
_container.RegisterType<DashboardView>();
_container.RegisterType<PrepareRunView>();
_container.RegisterType<IDashboardViewViewModel, DashboardViewViewModel>();
_container.RegisterType<IPrepareRunViewViewModel, PrepareRunViewViewModel>();
_regionManager.RegisterViewWithRegion(RegionNames.MainRegion, typeof(DashboardView));
_regionManager.RegisterViewWithRegion(RegionNames.MainRegion, typeof(PrepareRunView));
Moreover in module class when I register both the views for same region, I'm able to see both the views, so I need to activate and deactivate my views also.
Thanks in advance
Upvotes: 1
Views: 1285
Reputation: 10203
The view-model of the first view (the one where you select an employee) needs a reference to Prism's IRegionManager object. You navigate to the second view and pass it some data as follows, much like querystring values in a URL:-
var uriQuery = new UriQuery();
uriQuery.Add("empid", "123");
// Add more name/value pairs if you wish!
var viewName = "your_view_name" + uriQuery;
_regionManager.RequestNavigate("your region name", viewName);
As you can see, you navigate to a view by specifying a view name. For this to work, you need to register your views under a name with your IoC container (how you do this depends on which container you use).
In the view-model of the view you are navigating to, implement the INavigationAware interface:-
public bool IsNavigationTarget(NavigationContext navigationContext)
{
return true;
}
public void OnNavigatedFrom(NavigationContext navigationContext)
{
}
public void OnNavigatedTo(NavigationContext navigationContext)
{
// This will be called whenever the view is navigated to.
// Extract the querystring value(s).
var employeeId = navigationContext.Parameters["empid"];
.. etc..
}
Upvotes: 1
Reputation: 1196
You can use event aggregator for communication
http://msdn.microsoft.com/en-us/library/ff921122.aspx
Upvotes: 0