开发者

how to save and load a object in a windows phone 7 app?

is it possible in 开发者_开发百科a WP7 app to save some objects which i create and then load it when the app is started again?


You'll want to look to store persistent items into IsolatedStorage. You can see an overview and an example of how to use IsolatedStorage here. There are also a range of examples on this site, showing how to save different types of objects.


Here's an example storing a string, but you should be able to store any type of object this way. Add IsolatedStorage to your references:

using System.IO.IsolatedStorage;

In your class:

private string myString;

In the Loaded event for your page:

try
{
    myString = (string)IsolatedStorageSettings.ApplicationSettings["myString"];
}
catch
{
    IsolatedStorageSettings.ApplicationSettings.Add("myString", "this value is a string");
}

and later, when you want to save:

IsolatedStorageSettings.ApplicationSettings["myString"] = myString;


try after the example code above to add this. IsolatedStorageSettings.ApplicationSettings.save

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜