I have the case in Prism where I support the SearchContract with View/ViewModel combination.
The problem is this: when I leave the Search Panel open and perform multiple searches, each individual search is placed on the Navigation Stack. This means that when the user hits the "GoBack" button, they see each previous search result until they reach the original form that was being displayed before search was initiated.
I want the GoBack button to navigate back to the first page prior to Search.
I see a couple of possibilities:
One approach is to navigate.GoBack() on the SearchPage.OnNavigatedTo event when the navigation mode is 'Back.
public override async void OnNavigatedTo(object navigationParameter, Windows.UI.Xaml.Navigation.NavigationMode navigationMode, System.Collections.Generic.Dictionary<string, object> viewModelState)
{
if (navigationMode != NavigationMode.Back)
{
base.OnNavigatedTo(navigationParameter, navigationMode, viewModelState);
// ... and so on ...
}
else
{
if (this.navigationService.CanGoBack())
{
// this call must be run on the dispatcher due to using the async-void signature on this event
await Window.Current.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => this.navigationService.GoBack());
}
}
}
What's interesting here is the need to use the Dispatcher. Without it, the .GoBack() function fails. I'm not convinced this is the best answer, but it's an answer.