我正在制作一个笔记应用程序,用户可以在其中创建,编辑和删除笔记。应用关闭后,所有数据都应存储在独立的存储中。我创建了一个注释类,在下面设置了一些属性:
public string strNoteName { get; set; }
public string strCreated { get; set; }
public string strModified { get; set; }
public bool boolIsProtected { get; set; }
public string strNoteImage { get; set; }
public string strNoteSubject { get; set; }
public string strTextContent { get; set; }
将它们放到ObservableCollection<note> GetnotesRecord()
可以使用列表框显示在主页中的。触摸时,有一个事件处理程序,SelectionChange
可将项目传递到编辑页面,在该页面上可以编辑诸如strTextContent和strNoteName之类的项目。
添加完所有这些之后,我希望将数据保存到隔离存储中,以便下次应用程序运行时可以将其加载。
是否可以保存ObservableCollection<note>
?如果是,在以后启动应用程序时如何从隔离存储中检索它?
脚步 :-
如果集合很大,则将ObservalbleCollection转换为xml字符串,并使用IsolatedStorageSettings
class作为键值对进行存储。
如果不是:-,那么您可以像这样直接使用IsolatedStorageSettings
IsolatedStorageSettings Store { get { return IsolatedStorageSettings.ApplicationSettings; } }
public T GetValue<T>(string key)
{
return (T)Store[key];
}
public void SetValue(string token, object value)
{
Store.Add(token, value);
Store.Save();
}
用法:-
ObservableCollection<Note> objCollection = new ObservableCollection<Note>()
{
new Note(){Checkbool = false,Checkme = "sd"},
new Note(){Checkbool = false,Checkme = "sd1"},
new Note(){Checkbool = false,Checkme = "sd2"}
};
// you can also make check whether values are present or
// by checking the key in storage.
var isContainKey = Store.Contains("set")
// save key value pair
SetValue("set", objCollection);
// extract key value pair
var value = GetValue<ObservableCollection<Note>>("set");
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句