OnNavigatedTo happens BEFORE RestorableState values are set

Sep 3, 2013 at 2:33 AM
Edited Sep 3, 2013 at 3:43 PM
I Suspend and Shutdown, then start the app back up.
I would expect my RestorableState properties to be set before the OnNavigatedTo method.

I want a filter property to be set (RestorableState) before OnNavigatedTo so that the OnNavigatedTo can call my LoadData method with gets my collection using the filter property.

It appears that the constructor is called, then OnNavigatedTo and then the RestorableState props get populated. Isn't this backwards?
Sep 3, 2013 at 5:04 PM

Are you invoking the base implementation of the OnNavigatedTo method? Based on my understanding, the base implementation of this method should populate the properties marked with the RestorableState property if the viewModelState parameter is not null. Hence, you could try to invoke it inside your OnNavigatedTo method before loading the data:
public override async void OnNavigatedTo(object navigationParameter, NavigationMode navigationMode, Dictionary<string, object> viewModelState)
    base.OnNavigatedTo(navigationParameter, navigationMode, viewState);
The values of the properties that need to be restored are passed in the viewModelState. If the property is not being set, you could check viewModelState parameter to see if the value of the property was loaded correctly and, if needed, obtain the value directly from it.

Please, let us know if this solves the problem you are experiencing.
I hope this helps,

Damian Cherubini
Sep 3, 2013 at 5:57 PM
Damian, that is very helpful. I think I am calling base AFTER I call load data. So I will move the call to base before my code.

Thank you very much.
Oct 30, 2014 at 3:34 PM
The base implementation populates the properties marked RestorableState if the viewModelState parameter is not null.
Thank you! When I am king, you, my friend, will be well taken care of... ;-)
// Jerry