创建框架
像任何其他控件一样创建框架:
<Frame x:Name="contentRoot"
Navigated="OnNavigated"
Navigating="OnNavigating" />
然后可以拦截导航/导航事件以取消导航或显示/隐藏后退按钮。
private void OnNavigating(object sender, NavigatingCancelEventArgs e)
{
if(contentRoot.SourcePageType == e.SourcePageType && m_currentPageParameter == e.Parameter)
{
// we are navigating again to the current page, we cancel the navigation
e.Cancel = true;
}
}
private void OnNavigated(object sender, NavigationEventArgs e)
{
// user has navigated to a newest page, we check if we can go back and show the back button if needed.
// we can also alter the backstack navigation history if needed
SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = (contentRoot.CanGoBack ? AppViewBackButtonVisibility.Visible : AppViewBackButtonVisibility.Collapsed);
}