Given A Prism 7 UWP Application with three Views and corresponding ViewModels:
containerRegistry.RegisterForNavigation<BlankPage1, BlankPage1ViewModel>();
containerRegistry.RegisterForNavigation<BlankPage2, BlankPage2ViewModel>();
containerRegistry.RegisterForNavigation<BlankPage3, BlankPage3ViewModel>();
If we navigate from BlankPage1 to BlankPage2 passing a parameter (from within a Command in ViewModel1):
public virtual DelegateCommand GoToPage2Command => new DelegateCommand(GoToPage2);
public virtual async void GoToPage2() {
await NavigationService.NavigateAsync("BlankPage2", null, ("param", 5678));
}
In the OnNavigatedToAsync override of BlankPage2ViewModel the parameter is correctly passed in.
Now if we navigate from BlankPage2ViewModel to BlankPage3ViewModel, via a Command and pass another Parameter
public virtual DelegateCommand GoToPage3Command => new DelegateCommand(GoToPage3);
public virtual async void GoToPage3() {
await NavigationService.NavigateAsync("BlankPage3", null, ("param", 1234));
}
Again this works and the parameter value 1234 is passed to BlankPage3ViewModel.
Now however if we navigate back to BlankPage2ViewModel:
await NavigationService.GoBackAsync();
No parameters are passed back into the OnNavigatedToAsync override of BlankPage2ViewModel. Surely we would expect to see the parameter value 5678?
NOTE: We also set NavigationCacheMode to Required inside each view.
An answer to a question asked over on the MSDN forums, regarding a similar issue states:
If you use Frame.Navigate to navigate to the same page, your PageA won't be reinstanciated but the OnNavigatedTo method will be called with the new parameters.
That way, you can change the information displayed on the page (even play some transition if needed); and as an added bonus the Frame history does keep your previous PageA parameters, allowing you to call Frame.GoBack to return to the previous PageA state.
Is this by design in Prism that no parameters are passed back or a potential bug?
