专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > WinRT Metro

UWP 系统级页面领航

发布时间:2011-06-23 13:55:56 文章来源:www.iduyao.cn 采编人员:星星草
UWP 系统级页面导航

UWP之前,要实现应用内页面后退,Win8.1要自己弄一个后退按钮,WP8.1还可以选择Handle后退按钮事件。

而在UWP中,后退的实现变得更加方便。

在Windows.UI.Core命名空间里,有SystemNavigationManager这么个东西,

只需handle它的BackRequested事件,就可以响应各种系统级的后退事件了,

包括:UWP应用标题栏的后退按钮,Win10平板模式下任务栏上的后退按钮,Win10m的硬件后退按钮,快捷键Win+Backspace, 以及用Cortana触发的后退事件。

1 SystemNavigationManager.GetForCurrentView().BackRequested += 
2     App_BackRequested;
private void App_BackRequested(object sender, BackRequestedEventArgs e)
{
    Frame rootFrame = Window.Current.Content as Frame;
    if (rootFrame == null)
        return;

    // Navigate back if possible, and if the event has not 
    // already been handled .
    if (rootFrame.CanGoBack && e.Handled == false)
    {
        e.Handled = true;
        rootFrame.GoBack();
    }
}

另外,标题栏的后退按钮可以通过SystemNavigationManager来控制是否显示。

  if (rootFrame.CanGoBack)
            {
                // If we have pages in our in-app backstack and have opted in to showing back, do so
                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
            }
            else
            {
                // Remove the UI from the title bar if there are no pages in our in-app back stack
                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
            }

话说这东西我翻文档翻了半天才找到...

参考:https://msdn.microsoft.com/en-us/library/windows/apps/mt465734.aspx

友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: