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.
whihathac
source share