简体   繁体   English

Windows Phone导航而不创建Uri的新实例

[英]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.

相关问题 哪个Windows Phone 7模拟器是新的? - Which Windows Phone 7 emulator is new? 为Windows Phone秒表计时器创建暂停按钮 - Creating Pause Button for Windows Phone Stopwatch timer 在 Windows Phone 7 (WP7) 中以编程方式创建按钮 - Creating a button programmatically in Windows Phone 7 (WP7) 创建Windows Phone应用,Expression Blend和Visual Studio时的工作流程 - Workflow when creating a Windows Phone App, Expression Blend and Visual Studio 如何在不安装Windows Phone 8 SDK的情况下针对Windows Phone 8创建可移植库类? - How to create a portable library class targeting Windows Phone 8 without installing the Windows Phone 8 SDK? 创建新的SL4导航应用时出现编译错误 - compile error when creating a new SL4 navigation app “添加新项”选项中未显示“ Windows 7 Phone的Silverlight”选项 - “silverlight for Windows 7 Phone” option is not shown in “Add new Item” option 从库创建DLL,无需任何新代码 - Creating a DLL from libs without any new code 我是否需要为新的Windows Phone 7系列开发支付版本的Visual Studio? - Do I need a paid-for version of Visual Studio to develop for the new Windows Phone 7 Series? 是否可以在没有Express的情况下在VS2010 Pro中安装Windows Phone 7工具 - Is it possible to install Windows Phone 7 tools in VS2010 Pro without Express
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM