zoukankan      html  css  js  c++  java
  • UWP-标题栏”后退“按钮

    标题栏”后退“按钮,系统级导航

      应用必须启用所有硬件和软件系统后退按钮的后退导航。执行此操作的方法是注册 BackRequested 事件的侦听器并定义相应处理程序。

      在此处我们为 App.xaml 代码隐藏文件中的 BackRequested 事件注册全局侦听器。如果你想要从后退导航排除特定页面,或想要在显示页面前执行页面级别代码,可以在每个页面中注册此事件。

    Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested +=   App_BackRequested; 
    

      

      以下是在应用的根框架上调用 GoBack 的相应 BackRequested 事件处理程序。

      此处理程序在全局后退事件上调用。 如果应用内后退堆栈为空,系统可能导航至 应用堆栈中的上一个应用或“开始”屏幕。 桌面模式没有应用后退堆栈,并且即使在应用内后退堆栈耗尽时,用户也将停留在该应用中。

    private void App_BackRequested(object sender,  
        Windows.UI.Core.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(); 
        } 
    }
    

      

    启用标题栏后退按钮

    支持桌面模式(通常是 PC 和笔记本电脑,但也有一些平板电脑)并启用了设置(“设置”>“系统”>“平板电脑模式”)的设备不提供带有系统后退按钮的全局导航栏。

    在桌面模式下,每个应用都在带有标题栏的窗口中运行。你可以为在此标题栏中显示的应用提供备用后退按钮。

    标题栏后退按钮仅在桌面模式下的设备上运行的应用中可用,并且仅支持应用内导航历史记录—它不支持应用间的导航历史记录。

    要点  默认情况下不显示标题栏后退按钮。你必须选择显示该按钮。
     

    在隐藏代码文件中,为你想要启用标题栏后退按钮的每个页面重写 OnNavigatedTo 事件并将 AppViewBackButtonVisibility 设置为 Visible

    例如,如果帧的 CanGoBack 属性值为 true,我们将在后退堆栈中列出每个页面并启用后退按钮。

    protected override void OnNavigatedTo(NavigationEventArgs e) 
    { 
        Frame rootFrame = Window.Current.Content as Frame; 
     
        string myPages = ""; 
        foreach (PageStackEntry page in rootFrame.BackStack) 
        { 
            myPages += page.SourcePageType.ToString() + "
    "; 
        } 
        stackCount.Text = myPages; 
     
        if (rootFrame.CanGoBack) 
        { 
            // Show UI in title bar if opted-in and in-app backstack is not empty. 
            SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =  
                AppViewBackButtonVisibility.Visible; 
        } 
        else 
        { 
            // Remove the UI from the title bar if in-app back stack is empty. 
            SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =  
                AppViewBackButtonVisibility.Collapsed; 
        } 
    } 
    

      摘自:MSDN

  • 相关阅读:
    【笔记】进化型开发方法
    错误注入学习笔记
    【C/C++】关于编译错误 "error C2146: syntax error : missing ';' before identifier 'xxx'"
    查找进程加载到内存中的EntryPoint
    devepxress qtp 点击子菜单
    RijndaelManaged 自定义key和iv
    sql server transaction
    使用gzip压缩字符串
    tsql 与时间(周)相关的一些操作
    excel 合并单元格
  • 原文地址:https://www.cnblogs.com/zhuyulong/p/5515656.html
Copyright © 2011-2022 走看看