Background
In the Windows Phone 8 development process, tombstone's processing really makes us love and hate, and it can makeProgramIt seems to be running all the time. However, it is very troublesome to process the tombstone. In the traditional method, we need to put the state to be saved after the deactived event of the program is triggered, and then load the state after the user returns. However, if our program adopts the mvvm architecture, the situation will be more complicated. I believe everyone will understand the complexity. Let's continue to look at the Magic tombstone processing in the CM framework.
From simpleCodeStart:
On the test page, we add a textbox named name:
Then add the name attribute to viewmodel to implement the INPC interface.
In this case, when the user enters the information in the textbox and the tombstone returns, the input in the textbox is still the content in front of the tombstone. Analyze the problem from the problem:
1. What is storagehandler used?
This class is the class for processing the tombstone. CM will reflect all classes that inherit this class when the program starts, and then process it. After the program deactived, the configuration property is automatically saved to the state. When the program starts again, the property is restored to the viewmodel.
2. What are the property and inphonestate functions?
These two functions are used to configure the location of the corresponding attribute in viewmodel. For example, in the code above, the name attribute is put into the state for saving.
3. Do I only need these codes?
We need to call registerphoneservices In the configure of bootstrapper. This function will register the class for tombstone processing for our operations.
Summary
CM is indeed a class library worthy of in-depth research. The author's idea of solving the problem is worth learning, and many implementation methods are also a good place for us to learn the syntax.
In terms of usage, CM provides additional support for the WP system, making it the best choice for the WP app mvvm architecture.
QQ chat group: 182659848