Win10的UWP之标题栏的返回键(一)
生活随笔
收集整理的這篇文章主要介紹了
Win10的UWP之标题栏的返回键(一)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
原文:Win10的UWP之標題欄的返回鍵(一)
關于返回鍵,放在標題欄是目前較為完美的一種方案。繼前一篇的Hello World,博主進行一些修改實現該方法。
- - - - - - - - - - - - - - - - - - - - - - - 我是萬惡的分割線- - - - - - - - - - - - - - - - - - -
在OnLaunched的方法中加
Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += BackRequested;緊接著在加一段代碼
SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = rootFrame.CanGoBack ? AppViewBackButtonVisibility.Visible : Windows.UI.Core.AppViewBackButtonVisibility.Collapsed;rootFrame.Navigated += OnNavigated;我們在繼續把代碼寫完用兩個方法來適配前面寫的兩段代碼
private void OnNavigated(object sender, NavigationEventArgs e){SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = ((Frame)sender).CanGoBack ? AppViewBackButtonVisibility.Visible : AppViewBackButtonVisibility.Collapsed;} private void BackRequested(object sender, BackRequestedEventArgs e){Frame rootFrame = Window.Current.Content as Frame;if (rootFrame == null)return;if (rootFrame.CanGoBack && e.Handled == false){e.Handled = true;rootFrame.GoBack();}}為了能夠看見效果,我們另外添加了一個頁面
然后主界面的代碼如下
基本的都做完了我們來看一下效果怎么樣
總結
以上是生活随笔為你收集整理的Win10的UWP之标题栏的返回键(一)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: AngularJS例子 ng-repea
- 下一篇: 文章已转移到“字符集编码与乱码”分类下