在我的WP7应用程序中,我正在做:
string userName = IsolatedStorageSettings.ApplicationSettings.Contains("UserName") ? IsolatedStorageSettings.ApplicationSettings["UserName"].ToString() : null;
if (string.IsNullOrEmpty(userName))
IsolatedStorageSettings.ApplicationSettings["UserName"] = "test";
我启动了我的应用程序(F5),当然,userName为空,因此它存储在独立存储中。
我停止了我的应用程序(停止调试),我没有关闭模拟器
再次启动我的应用程序(F5),但仍然是空的。
我已经读过,隔离存储应该在模拟器未关闭时保持不变。
我做错了什么?
提前感谢您的回答。
答案 0 :(得分:6)
你还需要打电话
IsolatedStorageSettings.ApplicationSettings.Save();
更改设置后。
答案 1 :(得分:4)
您是否尝试过正常退出应用程序? (通过按下模拟器中的后退按钮,而不是按下Visual Studio中的“停止”按钮)。我认为在应用程序退出时会保存IsolatedStorageSettings.ApplicationSettings的内容。 Visual Studio的“停止”按钮会杀死应用程序,从而阻止保存代码运行。