[英]Back button controlling for my Windows Phone 8.1 Silverlight App
I am developing a Windows Phone 8.1 Silverlight app. 我正在开发Windows Phone 8.1 Silverlight应用程序。 In my app, I need to override the back button code. 在我的应用中,我需要覆盖后退按钮代码。
So I tried this, 所以我尝试了
protected override void OnBackKeyPress(CancelEventArgs e)
{
//Navigating to this page when back button is pressed
DisplayPage mynewPage = new DisplayPage();
this.Content = mynewPage;
e.Cancel = true;
}
But this code is not working. 但是此代码不起作用。 What am I doing wrong? 我究竟做错了什么? Please help me out. 请帮帮我。
EDIT: 编辑:
When I place this code on MainPage, it works! 当我将此代码放在MainPage上时,它可以工作! But I don't want to place it there. 但是我不想把它放在那里。 I want to place it on other pages. 我想把它放在其他页面上。
Remove "e.Cancel = true" (it cancels the navigation). 删除“ e.Cancel = true”(它将取消导航)。 Simply just navigate to the new page. 只需浏览至新页面即可。
EDIT: 编辑:
For navigating to another page, I would rather suggest using NavigationService. 要导航到另一个页面,我建议使用NavigationService。 Check out this page for examples. 查看此页面以获取示例。
EDIT: 编辑:
Code snippet: 程式码片段:
protected override void OnBackKeyPress(CancelEventArgs e)
{
//Navigating to this page when back button is pressed
NavigationService.Navigate(new Uri("/DisplayPage.xaml", UriKind.Relative));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.