个人资料

主页 博客 留言板 搜索
跳过导航链接首页 > 博客列表 > 博客正文

UWP设置SystemNavigationManager自动导航禁止某个页面显示返回按钮

分类

自动导航一般在OnLaunched方法中,订阅事件:

rootFrame.Navigated += Show_Navigation;

事件如下,使用SystemNavigationManager显示后退键

// 方式 1
if ((Window.Current.Content as Frame).SourcePageType.Name== "MainPage")
{
    SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
}
else
{
    if ((Window.Current.Content as Frame).BackStack.Any())
    {
        SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
    }
    else
    {
        SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
    }
}
 
// 方式 2
// stack为后进先出。如mainpage页面跳走
//var plist = (Window.Current.Content as Frame).BackStack;
//var count = plist.Count;
//if (count > 0)
//{
//    if (plist[count - 1].SourcePageType.Name == "MainPage")
//    {
//        SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
//    }
//    else
//    {
//        SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
//    }
 
//}


但是如果想要在主页不显示后退键的话,判断BackStack栈页面的name属性,例如想要MainPage页面不要显示后退键,代码如上所示.

songshizhao
最初发表2018/6/6 22:52:10 最近更新2018/6/6 22:52:10 523
为此篇作品打分
10