Page constructor gets called again when navigating back in Windows 8 C# App

孤人 提交于 2019-12-04 22:54:32

问题


I have found that in Windows 8 apps, a Page's constructor always gets called again when navigating back to this page, however this is not the case in Windows Phone 7 apps.

Because of this behavior all the properties of that page get lost and you need to somehow store them and reassign them after the page is reactivated. At the moment I am using the SaveState method to save the data and reassign the data in LoadState method. Both of the methods are built-in in the sample Grid/Split App.

I wonder why it's designed this way and if there's any better way to maintain the instance of the page?


回答1:


You can set Page.NavigationCacheMode = NavigationCacheMode.Required for each page you want to keep in memory, but note that you have to make sure users can't navigate through these pages endlessly as that would leak memory.



来源:https://stackoverflow.com/questions/12633758/page-constructor-gets-called-again-when-navigating-back-in-windows-8-c-sharp-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!