Windows Phone 7: Professional Tips - Storing your settings

In Windows Phone 7, there are two ways to store values: State and IsolatedStorageSettings, which have their various pros and cons. I prefer to use IsolatedStorageSettings for most scenarios, but this tip applies to both, so when you see the code referring to one, it will work on both.

Very simply, the first setting you should store is one called version (or similar), and it should have a version indicator. In short, it tells you what version of the settings you are working with!

IsolatedStorageSettings.ApplicationSettings["version"] = "1";

Having this field has two advantages for you. First, it gives you a very simple way to check if settings are available—and if not, your app is running for the first time:

if (IsolatedStorageSettings.ApplicationSettings.Contains("version"))
{
    // do something with settings
}

The other advantage is that when you update your application, you can upgrade settings easily.

if (IsolatedStorageSettings.ApplicationSettings.Contains("version"))
{
    switch ((int)IsolatedStorageSettings.ApplicationSettings["version"])
    {
        case 1:
            // upgrade version setting and add missing settings or change existing settings
            break;
        case 2:
            // normal reading of settings
            break;
    }
}

Even if you never use it for upgrades, at least it’s there for a simple check. And if one day you need it—you’re ready to go!