[英]Windows Phone navigation without creating new instances of Uri
The way I understand Windows Phone 7 navigation is that each time you want to go to another page you use the following: 我了解Windows Phone 7导航的方式是,每次要转到另一个页面时,请使用以下命令:
this.NavigationService.Navigate(new Uri("/SecondPage.xaml", UriKind.Relative));
After going back and forth between pages (4 for example) will this not create a huge amount of objects over time; 在页面之间来回切换(例如4个)后,随着时间的推移,这不会创建大量的对象; Being that you are creating a New one each and everytime?
是不是您每次都在创建一个新的? Would this turn into an 'out of memory' issue?
这会变成“内存不足”的问题吗? I just want to make sure I understand the structure of how this works before proceeding further with any development.
我只想确保在进一步进行任何开发之前,先了解其工作原理。
You use NavigationService.Navigate
when navigating forward, but NavigationService.GoBack
when going back. 向前
NavigationService.Navigate
时使用NavigationService.Navigate
,而向后NavigationService.GoBack
时使用NavigationService.Navigate
。 Therefore, the backstack shouldn't grow indefinitely. 因此,堆栈不应无限期增长。
Also, if you need to reach the main page again after a forward cycle (MainPage -> Page1 -> Page2 -> MainPage), it's a good practice to clear the back stack. 另外,如果您需要在向前循环(MainPage-> Page1-> Page2-> MainPage)之后再次到达主页,则清除后退堆栈是一个好习惯。 This way, the user will be able to exit the application with a single press on the back button, instead of going through all the cycle again.
这样,用户只需按一下后退按钮就可以退出应用程序,而不必再次经历所有循环。 To remove a page from the back stack, use
NavigationService.RemoveBackEntry()
: 要从后堆栈中删除页面,请使用
NavigationService.RemoveBackEntry()
:
while (this.NavigationService.BackStack.Any())
{
this.NavigationService.RemoveBackEntry();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.