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, ...

Get Windows® Phone 8 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.