简体   繁体   English

WP7页面导航?

[英]WP7 page navigation?

Initially I am navigating from one to another XAML class like this (for example, from MainPage.xaml to Firstpage.xaml): 最初我正在从一个XAML类导航到另一个XAML类(例如,从MainPage.xaml到Firstpage.xaml):

 this.NavigationService.Navigate(new Uri("/Firstpage.xaml", UriKind.Relative));

This works fine, but I want to exit the application when hitting the back button. 这工作正常,但我想在按下后退按钮时退出应用程序。 When I navigate like this, the back button takes me back to the previous page (MainPage.xaml). 当我像这样导航时,后退按钮将我带回上一页(MainPage.xaml)。 How can I accomplish this? 我怎么能做到这一点?

You can use the RemoveBackEntry method to remove the page you come from. 您可以使用RemoveBackEntry方法删除您来自的页面。

http://msdn.microsoft.com/en-us/library/hh394012(v=VS.92).aspx http://msdn.microsoft.com/en-us/library/hh394012(v=VS.92).aspx

But in Windows Phone, navigation has to follow some rules. 但在Windows Phone中,导航必须遵循一些规则。 Remember that users expect to return to the previous page with the back button. 请记住,用户希望使用后退按钮返回上一页。 That's how navigation in Windows Phone is supposed to work. 这就是Windows Phone中的导航应该如何工作。 Except in a few cases. 除少数情况外。

If you just want your user to see a page once, when they launch the application, you can put the content of that page in a grid on your second page, and just hide it when it's not necessary. 如果您只是希望用户看到一次页面,那么当他们启动应用程序时,您可以将该页面的内容放在第二页的网格中,并在不需要时隐藏它。

In that way, when the user will hit the back button, the application will quit and you won't have to manipulate the navigation stack. 这样,当用户点击后退按钮时,应用程序将退出,您将不必操纵导航堆栈。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM