I wrote a simple wrapper around the IsolatedStorageSettings class that helps store and retrieve settings. Maybe you will find it useful.
using System.IO.IsolatedStorage;
public static class AppSettings
{
private static IsolatedStorageSettings Settings = System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings;
public static void StoreSetting(string settingName, string value)
{
StoreSetting<string>(settingName, value);
}
public static void StoreSetting<TValue>(string settingName, TValue value)
{
if (!Settings.Contains(settingName))
Settings.Add(settingName, value);
else
Settings[settingName] = value;
// EDIT: if you don't call Save then WP7 will corrupt your memory!
Settings.Save();
}
public static bool TryGetSetting<TValue>(string settingName, out TValue value)
{
if (Settings.Contains(settingName))
{
value = (TValue)Settings[settingName];
return true;
}
value = default(TValue);
return false;
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…