Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 706
Justin XL Avatar asked Sep 28 '12 04:09

Justin XL


1 Answers

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.

like image 190
Filip Skakun Avatar answered Nov 19 '22 19:11

Filip Skakun