How to transfer an object when navigating to a new view in PRISM 4

I am working on a PRISM application, where we go to the data (to get more details). In my implementation, I have a nested MVVM, and when I navigate the tree, I would like to pass the model to my newly created view.

As far as I know, PRISM currently allows the transfer of strings, but does not allow the transfer of objects. I would like to know what are the ways to overcome this problem.

+7
source share
3 answers

I usually use a service where I register objects that I want to pass with guid. they are stored in a hash table and when navigating in a prism I pass guid as a parameter that can then be used to retrieve the object.

Hope this makes sense to you!

+7
source

I would use the OnNavigatedTo and OnNavigatedFrom methods to transfer objects using the NavigationContext.

First output the model with the INavigationAware interface -

public class MyViewModel : INavigationAware { ... 

Then you can implement OnNavigatedFrom and set the object you want to pass as the navigation context, as follows -

 void INavigationAware.OnNavigatedFrom(NavigationContext navigationContext) { SharedData data = new SharedData(); ... navigationContext.NavigationService.Region.Context = data; } 

and when you want to get the data, add the following code snippet to the second view model -

 void INavigationAware.OnNavigatedTo(NavigationContext navigationContext) { if (navigationContext.NavigationService.Region.Context != null) { if (navigationContext.NavigationService.Region.Context is SharedData) { SharedData data = (SharedData)navigationContext.NavigationService.Region.Context; ... } } } 

ps. mark this as an answer if that helps.

+3
source

PRISM supports feed parameters:

 var para = new NavigationParameters { { "SearchResult", result } }; _regionManager.RequestNavigate(ShellRegions.DockedRight, typeof(UI.SearchResultView).FullName, OnNavigationCompleted, para); 

and implement the INavigationAware interface on your view, in the ViewModel, or both.

You can also find here: https://msdn.microsoft.com/en-us/library/gg430861%28v=pandp.40%29.aspx

+1
source

All Articles