private void DemoDataPersistenceCodeThroughSettings() { // Persisting simple Application Settings. localSettings.Values["CurrentReadingBook"] = "Migrating to Windows Phone"; roamingSettings.Values["LastPageReadOnCurrentBook"] = 20; // Organizing settings in containers. Windows.Storage.ApplicationDataContainer container = localSettings.CreateContainer("FavoriteBooks", Windows.Storage.ApplicationDataCreateDisposition.Always); if (localSettings.Containers.ContainsKey("FavoriteBooks")) { localSettings.Containers["FavoriteBooks"].Values["FavoriteWindowsPhoneBook"] = "Windows Phone Recipes"; } // Reading settings back. string currentBook = string.Empty; int lastPageReadOnCurrentBook; if (localSettings.Values["CurrentReadingBook"] != null) { currentBook = localSettings.Values["CurrentReadingBook"].ToString(); } if (roamingSettings.Values["LastPageReadOnCurrentBook"] != null) { lastPageReadOnCurrentBook = Convert.ToInt16(roamingSettings.Values["LastPageReadOnCurrentBook"]); } bool hasFavoritesContainer = localSettings.Containers.ContainsKey("FavoriteBooks"); string favoriteWindowsPhoneBook = string.Empty; if (hasFavoritesContainer) { if (localSettings.Containers["FavoriteBooks"].Values.ContainsKey("FavoriteWindowsPhoneBook")) { favoriteWindowsPhoneBook = localSettings.Containers["FavoriteBooks"].Values["FavoriteWindowsPhoneBook"].ToString(); } } // Deleting Settings from Storage. localSettings.Values.Remove("CurrentReadingBook"); roamingSettings.Values.Remove("LastPageReadOnCurrentBook"); localSettings.DeleteContainer("FavoriteBooks"); }
/// <summary> /// 删除容器 /// </summary> /// <param name="ContainerName">容器名字</param> public void RemoveContainer(Object ContainerName) { localSetting.DeleteContainer(ContainerName.ToString()); }
/// <summary> /// 删除设置容器 /// </summary> /// <param name="key"></param> public static void RemoveContainer(string containerName) { localSettings.DeleteContainer(containerName); }