您的位置:首页 > 移动开发

UWP 开发APP准备工作

2015-11-28 20:11 399 查看
每新建一个UWP之后,都要进行一番相同的处理步骤,才能使Mobile的使用体验更好,故总结如下:

1.订阅Mobile后退导航事件

在App.xaml.cs文件中OnLaunched方法中添加

SystemNavigationManager.GetForCurrentView().BackRequested += 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();
}
}


2.增加PC端的后退按钮

protected override void OnNavigatedTo(NavigationEventArgs e)
{
Frame rootFrame = Window.Current.Content as Frame;
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;
}
}


3.页面跳转时的缓存

NavigationCacheMode = Windows.UI.Xaml.Navigation.NavigationCacheMode.Required;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: