This is what I just learned.
This processing mechanism is very good, and the principle of the tombstone mechanism is somewhat different:
The tombstone mechanism is executed in application_launching, application_activated, application_deactivated, application_closing, and other methods of the app file, or in the background code onnavigatedfrom, onnavigatedto.
This article describes how to use isolatedstoragesettings in the background code for independent storage.
This example uses textbox as an example.
First, add a button on the mainpage and add an event to the click to jump to the new Add. XAML button in the form.
Before writing the Add. XAML file, you also need to judge how to add and load the mainpage background for the first time.
Assume that the user adds. after writing content on the XAML page, click the start button and return to the Start Screen, and then start the application. At this time, you need to determine whether the user has saved the content that was not saved last time.
First, add the following code to the loaded event:
Private void phoneapplicationpage_loaded (Object sender, routedeventargs E)
{
// First instantiate isolatedstoragesettings
Isolatedstoragesettings settings = isolatedstoragesettings. applicationsettings;
// Define a variable to store status information
String state = "";
// Check whether the status information "state" exists in isolatedstoragesettings"
If (settings. Contains ("state "))
{
// If yes, read the state information to the state variable.
If (settings. trygetvalue <string> ("State", out State ))
{
// Determine whether the obtained status information is "add ".
If (State = "add ")
{
// If the read status information is "add", if yes, it indicates that the user has not saved the content, the page will jump to the "Add. XAML" status page before closing.
Navigationservice. navigate (New uri ("/toubtest; component/Add. XAML", urikind. Relative ));
}
}
}
Isolatedstoragetextbox. Focus ();
}
The following is the initialization code on the Add. XAML page.
Define a global isolatedstoragesettings
Private isolatedstoragesettings settings = isolatedstoragesettings. applicationsettings;
Then initializing
Void add_loaded (Object sender, routedeventargs E)
{
String state = "";
// Determine whether the State is included.
If (settings. Contains ("state "))
{
// If it contains, the retrieved state is assigned to the State.
If (settings. trygetvalue <string> ("State", out State ))
{
// If the State content is add
If (State = "add ")
{
String value = "";
// Determine whether the value is included
If (settings. Contains ("value "))
{
// Retrieve Value
If (settings. trygetvalue <string> ("value", out value ))
{
// Display the value in the Textbox Control
This. addtextbox. Text = value;
}
}
}
}
}
// The content must be initialized in the following way to determine whether or not the State exists
Settings ["state"] = "add ";
Settings ["value"] = addtextbox. text;
Addtextbox. Focus ();
// Move the cursor to the end of the text
Addtextbox. selectionstart = addtextbox. Text. length;
}
Add the textchanged event to the textbox to save the status content in time.
Private void addtextbox_textchanged (Object sender, textchangedeventargs E)
{
Settings ["value"] = addtextbox. text;
}
Finally, add a clearing event to the backkeypress return button.
Private void phoneapplicationpage_backkeypress (Object sender, system. componentmodel. canceleventargs E)
{
// Clear the original state content add
Settings ["state"] = "";
}
Source code: http://vdisk.weibo.com/s/6MeYw