建立框架
像任何其他控制元件一樣建立框架:
<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);
}