繁体   English   中英

在IsolatedStorageSettings.ApplicationSettings中存储提醒

[英]Store Reminder in IsolatedStorageSettings.ApplicationSettings

我正在尝试将提醒存储在IsolatedStorage中。 它在运行时有效,但是如果我重新启动应用程序,所有数据都将消失。

这里有一些有趣的代码:

private IsolatedStorageSettings userSettings = IsolatedStorageSettings.ApplicationSettings;

private List<ScheduledAction> getStorage()
{
    if (!userSettings.Contains("notifications"))
    {
        userSettings.Add("notifications", new List<ScheduledAction>());
    }

    return (List<ScheduledAction>)userSettings["notifications"];
}
private void saveStorage(List<ScheduledAction> list)
{
    userSettings["notifications"] = list;
}

private void test()
{
    List<ScheduledAction> list = getStorage();
    Reminder alarm = new Reminder("name");
    list.Add(alarm);
    saveStorage(list);
}

我目前的猜测,为什么不存储对象是Reminder不能序列化。 由于这不是我的目标,我该怎么办?

每当我们在IsolatedStorageSettings.Save方法中添加或更新时,都需要在应用程序退出之前进行保存。 我对您的代码进行了很少的更改,可能会对您有所帮助。

private List<ScheduledAction> getStorage()
{
    if (!userSettings.Contains("notifications"))
    {
        userSettings.Add("notifications", new List<ScheduledAction>());
       userSettings.Save();
    }

    return (List<ScheduledAction>)userSettings["notifications"];
}

private void saveStorage(List<ScheduledAction> list)
{
    userSettings["notifications"] = list;
    userSettings.Save();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM