Charles Petzold のProgramming Windows Phoneのpp128に掲載されているパターンです。
using System.IO.IsolatedStorage;
…
private void Application_Launching(object sender, LaunchingEventArgs e)
{
LoadSettings();
}
private void Application_Activated(object sender, ActivatedEventArgs e)
{
LoadSettings();
}
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
SaveSettings();
}
private void Application_Closing(object sender, ClosingEventArgs e)
{
SaveSettings();
}
…
public int MyValue= 123;
public bool IsOk= false;
private void LoadSettings()
{
var settings = IsolatedStorageSettings.ApplicationSettings;
if (settings.TryGetValue<int>(“MyValue”, out MyValue) == false)
MyValue= 999;
if (settings.TryGetValue<bool>(“IsOk”, out IsOk) == false)
IsOk= false;
}
public void SaveSettings()
{
var settings = IsolatedStorageSettings.ApplicationSettings;
settings[“MyValue”] = MyValue;
settings[“IsOk”] = IsOk;
settings.Save();
}
(Application.Current as App).MyValue = 256;
(Application.Current as App).IsOk= true;
コメントを残す