O'Reilly logo

Windows® Phone 8 Unleashed by Daniel Vaughan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Customizing ViewModel State Preservation

A viewmodel has the opportunity to customize how its state is persisted by overriding the SaveState method from the ViewModelBase class, as shown:

public override void SaveState(    IDictionary<string, object> persistentDictionary,    IDictionary<string, object> transientDictionary){    base.LoadState(persistentDictionary, transientDictionary);    byte[] state = Serialize(items);    transientDictionary[itemsStateKey] = state;    transientDictionary[queryStateKey] = lastQuery;}

The Serialize and Deserialize methods of the ViewModelBase class are able to convert an object to and from an array. The serialization mechanism is discussed in more detail in the next section.

Conversely, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required