isolatedStorageSettings 需要更新吗?
我在 WP7 上使用isolatedStorageSettings 来存储对象列表:
List<T>
我需要搜索列表中的项目并更新搜索项目的一些属性。
我正在使用这段代码:
List<Article> listArt = null;
IsolatedStorageSettings.ApplicationSettings.TryGetValue("ArticleListStorage", out listArt);
var queryList = (from anItem in listArt where (anItem.Id == _id) select anItem).ToList<Article>();
a = queryList[0] as Article;
//mark Article as read
a.Readed = true;
当我连续导航应用程序内的各个页面时,我可以看到正确评估了 Readed 属性。
但是,当我单击 WP7“开始”按钮并重新打开我的应用程序(不关闭模拟器)时,我发现该属性未正确评估。
我需要更新列表中的对象以及独立存储中的对象吗?
没有通过参考更新?
我也尝试过这个,但它不起作用:
listArt[0].Readed = true;
listArt[0].Favorite = true;
IsolatedStorageSettings.ApplicationSettings["ArticleListStorage"] = listArt;
IsolatedStorageSettings.ApplicationSettings.Save();
出了什么问题?
太感谢了!
I'm using IsolatedStorageSettings on WP7 to store an objects list:
List<T>
I need to search an item inside my list and to update some properties of the searched item.
I'm using this code:
List<Article> listArt = null;
IsolatedStorageSettings.ApplicationSettings.TryGetValue("ArticleListStorage", out listArt);
var queryList = (from anItem in listArt where (anItem.Id == _id) select anItem).ToList<Article>();
a = queryList[0] as Article;
//mark Article as read
a.Readed = true;
When I continuously navigate the various page inside the app, I can see the property Readed correctly evalued.
But, when I click on WP7 Start button and reopen my app (without close emulator) I see the property not correctly evalued.
Need I to update my object inside list and so inside Isolated Storage?
Not updated by reference?
I tried also this, ant it doesn't work:
listArt[0].Readed = true;
listArt[0].Favorite = true;
IsolatedStorageSettings.ApplicationSettings["ArticleListStorage"] = listArt;
IsolatedStorageSettings.ApplicationSettings.Save();
What is wrong?
Thank you so much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以显式调用
作为一般规则,我建议在更改设置后始终明确保存设置。 (除非您有充分的理由不这样做。)
您的情况是,您按下开始按钮,导致您的应用程序被逻辑删除。当您启动应用程序的新实例时,逻辑删除版本将被销毁,而不会执行通常在应用程序关闭时运行的所有代码(包括自动保存设置)。
这是使用“保存”的示例:
You can either explicitly call Save() on the settings or wait for the app to close normally and then they will be saved automatically.
As a general rule I'd suggest always explicitly saving settings once you change them. (Unless you have a very good reason not to.)
What's happening in your situation is that you are pressing the start button which causes your app to tombstone. When you launch a new instance of the app the tombstoned version is destroyed without all the code which normally runs on application close (including auto-saving settings) being executed.
Here's and example of using Save:
是的,您必须再次保存您的列表。将独立存储视为文件系统 - 您不会期望能够从磁盘加载
XDocument
、在内存中进行更改并自动看到磁盘上反映的这些更改,你愿意吗?嗯,隔离存储也是如此。Yes, you've got to save your list again. Think of isolated storage as a file system - you wouldn't expect to be able to load an
XDocument
from disk, make changes in memory and automatically see those changes reflected on disk, would you? Well, it's the same with isolated storage.