The problem comes from the NavigationHelper OnNavigateTo method
public void OnNavigatedTo(NavigationEventArgs e) { var frameState = SuspensionManager.SessionStateForFrame(this.Frame); this._pageKey = "Page-" + this.Frame.BackStackDepth; if (e.NavigationMode == NavigationMode.New) { // Clear existing state for forward navigation when adding a new page to the // navigation stack var nextPageKey = this._pageKey; int nextPageIndex = this.Frame.BackStackDepth; while (frameState.Remove(nextPageKey)) { nextPageIndex++; nextPageKey = "Page-" + nextPageIndex; } // Pass the navigation parameter to the new page if (this.LoadState != null) { this.LoadState(this, new LoadStateEventArgs(e.Parameter, null)); } } else { // Pass the navigation parameter and preserved page state to the page, using // the same strategy for loading suspended state and recreating pages discarded // from cache if (this.LoadState != null) { this.LoadState(this, new LoadStateEventArgs(e.Parameter, (Dictionary<String, Object>)frameState[this._pageKey])); } } }
if (e.NavigationMode == NavigationMode.New) , if always true, because Frame creates a new instance of Page by default. See Frame Class Notes . Thus, the LoadState event handler is always called with the zero state parameter
if (this.LoadState != null) { this.LoadState(this, new LoadStateEventArgs(e.Parameter, null)); }
Now, if you look at the full PhotoPage.xaml code, you will notice that there is this NavigationCacheMode="Enabled" in the page header that is what PhotoPage .
It is not necessary that all codes store states in Page . Frame class does this for you when Page sets its NavigationCacheMode .
source share