一种方法是在导航模式为“返回”时在 SearchPage.OnNavigatedTo 事件上导航.GoBack()。
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());
}
}
}
这里有趣的是需要使用 Dispatcher。没有它, .GoBack() 函数就会失败。我不相信这是最好的答案,但这是一个答案。