Background
Tombstone in the development process of Windows Phone 8 really makes us love and hate, it can make the program seems to be running. But dealing with tombstones is a very troublesome thing, the traditional way we need to be in the program Deactived event triggered, the need to save the state to put in, and then the user back to load out. And if our program uses the MVVM architecture, the situation will be more complex and complex. Believe that everyone has experience. Without saying much, let's continue to look at the magical tombstone in the CM framework.
Start with simple code:
On the test page, we add a textbox named Name:
Then add the Name property to the ViewModel to implement the INPC interface.
Only so, when the user enters the message into the textbox, the tombstone returns, and the input in the textbox remains the tombstone's content. Still analyze the problem from the question:
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/
1. What is Storagehandler for?
This class is the class that handles tombstones, and when the program starts, it reflects all classes that inherit this class, then processes it, and when the program deactived, it automatically stores the configured properties in state, and when the program starts again, it reverts back to the ViewModel
2, property function and Inphonestate function?
These two functions are used to configure which of the corresponding attributes in the ViewModel are placed where, for example, the Name property is stored in the state in the preceding code
3, just need this code?
We're going to call registerphoneservices in Bootstrapper's configure, which registers the class for tombstone processing for our operations.
Summarize
CM is a really worthy of in-depth study of a class library, the author of the idea of solving problems is worth our learning, and many methods of implementation is also a good place for us to learn grammar.
And in terms of use, CM for WP system provides additional support, so that it becomes WP APP MVVM architecture of the choice.