简体   繁体   中英

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:

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; 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. 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. 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() :

while (this.NavigationService.BackStack.Any())
{
   this.NavigationService.RemoveBackEntry();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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