isolatedStorageSettings 需要更新吗?

发布于 2024-10-05 04:42:01 字数 911 浏览 2 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤独患者 2024-10-12 04:42:01

您可以显式调用

作为一般规则,我建议在更改设置后始终明确保存设置。 (除非您有充分的理由不这样做。)

您的情况是,您按下开始按钮,导致您的应用程序被逻辑删除。当您启动应用程序的新实例时,逻辑删除版本将被销毁,而不会执行通常在应用程序关闭时运行的所有代码(包括自动保存设置)。

这是使用“保存”的示例:

var settings = IsolatedStorageSettings.ApplicationSettings;

if (settings.Contains("some-key"))
{
    settings.Remove("some-key");
}

settings.Add("some-key", "my-new-value");
settings.Save();

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:

var settings = IsolatedStorageSettings.ApplicationSettings;

if (settings.Contains("some-key"))
{
    settings.Remove("some-key");
}

settings.Add("some-key", "my-new-value");
settings.Save();
森林迷了鹿 2024-10-12 04:42:01

是的,您必须再次保存您的列表。将独立存储视为文件系统 - 您不会期望能够从磁盘加载 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文