1、Application Data簡介windows
Applicaion Data至關於桌面應用的註冊表,存儲一些用戶配置信息,如運行時狀態,用戶喜愛等,須要注意的時,當卸載應用時,這些數據會被刪除,因此不要存儲重要數據。服務器
Applicaion Data即便在應用更新之後也不會丟失,有一個版本控制。app
2、按用途分類ui
3、按存儲方式分類 this
App settingsspa
用ApplicationData.LocalSettings這個靜態屬性來取得ApplicationDataContainer類類型的配置。版本控制
App Filescode
用ApplicationData.LocalFolder這個靜態屬性來取StorageFolder類型的文件。blog
4、代碼示例get
存儲本地數據
ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;//存儲單一配置的句柄
ApplicationDataCompositeValue composite = new ApplicationDataCompositeValue();//存儲多項配置句柄 StorageFolder localFolder = ApplicationData.Current.LocalFolder;//存儲文件句柄
localSettings.Values[
"exampleSetting"] = "Hello Windows";;//存儲單一配置 composite["intVal"] = 1; composite["strVal"] = "string"; localSettings.Values["exampleCompositeSetting"] = composite;//存儲多項配置
創建配置層級
ApplicationDataContainer container =
localSettings.CreateContainer("exampleContainer", ApplicationDataCreateDisposition.Always); if (localSettings.Containers.ContainsKey("exampleContainer")) { localSettings.Containers["exampleContainer"].Values["exampleSetting"] = "Hello Windows"; }
讀取配置
Object value = localSettings.Values["exampleSetting"];//a setting ApplicationDataCompositeValue composite = (ApplicationDataCompositeValue)localSettings.Values["exampleCompositeSetting"]; if (composite == null) { // No data } else { // Access data in composite["intVal"] and composite["strVal"] } bool hasContainer = localSettings.Containers.ContainsKey("exampleContainer"); bool hasSetting = false; if (hasContainer) { hasSetting = localSettings.Containers["exampleContainer"].Values.ContainsKey("exampleSetting"); }
刪除配置
localSettings.Values.Remove("exampleSetting"); //ApplicationDataContainerSettings.Remove localSettings.Values.Remove("exampleCompositeSetting"); //ApplicationDataCompositeValue.Remove localSettings.DeleteContainer("exampleContainer"); //ApplicationDataContainer.DeleteContainer