简体   繁体   中英

how to manage the data in an xml file in wp7?

I have written a simple wp7 application. i am using wcf service to interact with the database. Now i want to store a part of user's info in the mobile also. this info needs to be accessible across the wp7 app.

I found multiple ways to do this like : isolated storage, resource files or static data in the app.xaml

Which one would be more suitable? as i may wish to edit the data in future...i may not opt for packaged files as they are read-only. also do not wish to lose data by storing in isolated storage.

Please suggest the most suitable option for me

Thanks in advance

Bindu

It sounds like you want to store downloaded data between uses of the app. In this case Isolated Storage is probably your best bet. It will remain in the phone's non-volatile memory and you will not lose it.

Details here

Resource files and static data in the app.xaml won't work for you since you want to be able to change these items at a later date since these will be read only.

I don't know what you are referring to when you say "lose data" by storing in IsolatedStorage. This is your best bet and is actually really easy to do. Here is an example of saving a simple boolean:

private void SaveSettings()
{
    IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
    settings["VibrationOn"] = VibrationOn;
}

Then to load it later:

private void LoadSettings()
{
    IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
    bool vo;  
    if (settings.TryGetValue<bool>("VibrationOn", out vo))
        VibrationOn = vo;
    else
        VibrationOn = true;
}

You would call your LoadSettings() method in the Application_Launching and Application_Activated events and then your SaveSettings() in the Application_Deactivated and Application_Closing events within your App.xaml.cs.

You can also serialize objects or write whole files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM