MainPageViewModel attributes not saving/restoring after tombstoning

Apr 10, 2011 at 1:08 AM

This is literally the last thing I need to get working on my WP7 app before it's finished, so naturally it's giving me trouble...

I was able to implement the [SurviveTombstone] attribute on one of my viewmodels, and it's working perfectly. A second viewmodel, however, appears to be completely ignoring the attributes. I have included the [SurviveTombstone] attribute on both the class and the properties that I want to save. The properties themselves are simple--a bool, an int, and a long. They have public getters and setters. The values are set properly before the app tombstones. In one case, there's nothing else that could overwrite the property--I made it just for the purpose of tombstoning a piece of data.

I even tried persisting a test string property that I set with a hardcoded value in the constructor, and it comes up null when the app resumes.

The only difference I can find between the two classes is that I am calling the method that is trying to use the properties from the viewmodel's constructor. Are tombstoned properties restored after the constructor completes?

Is there anything else I need to set that is easy to overlook?

Apr 10, 2011 at 4:32 AM

Tombstoned data is definitely restored after the ctor. You should probably wait to execute that code until after OnActivate or OnViewLoaded.  FYI, I know tombstoning is painful and hope to come up with something that's even better for vNext.

Apr 10, 2011 at 1:33 PM

Ah, thanks for the clarification.

This seems to be presenting me with another problem, though. Is there another way to get access to the OnActivate and OnViewLoaded methods, other than inheriting from Conductor<IScreen>.Collection.OneActive? I'm already inheriting from PropertyChangedBase on this page.

Apr 10, 2011 at 1:39 PM

OK, I think I got it. I substituted INotifyPropertyChangedEx for the PropertyChangedBase inheritance. The properties are still not restoring for some reason, but I think I'm further along than I was. Further debugging to follow. Thanks!