我正在构建Windows Phone 8.1 Silverlight应用程序。我可以使用以下注册表:
Windows.Storage.ApplicationData.Current.LocalSettings;
IsolatedStorageSettings.ApplicationSettings;
答案 0 :(得分:0)
Windows.Storage.ApplicationData.Current.LocalSettings
和IsolatedStorageSettings.ApplicationSettings
之间的区别在于,第一个是较新的统一Windows应用商店应用API,而后者来自“旧的”Silverlight API。
新的并不总是更好,但我个人认为你应该选择modern version。两者都可以使用Silverlight,但是如果您必须将代码迁移到WinRT,那么由于IsolatedStorageSettings
API在WinRT下不起作用,您将节省一些时间。
答案 1 :(得分:0)
使用这两种设置存在巨大差异:
IsolatedStorageSettings的工作方式类似于词典,并且已将其序列化并保存到 IsolatedStorageFile :
IsolatedStorageSettings提供了一种将用户特定数据作为键值对存储在本地IsolatedStorageFile中的便捷方式。
另请注意 IsolatedStorageSettings 必须保存 - IsolatedStorageSettings.Save。保存后,您将在应用程序的独立存储中找到 __ ApplicationSettings 文件。
ApplicationData.LocalSettings是ApplicationDataContainer。一旦你添加了一个值,它就会自动保存。它的模型is conceptually equivalent to the Windows registry。
所以它们完全不同,如果你在上面的设置中添加一个键,那么它就不会自动出现在第二个。考虑两个按钮:
const string firstKey = "firstKey";
const string secondKey = "secondKey";
IsolatedStorageSettings isoSetting = IsolatedStorageSettings.ApplicationSettings;
ApplicationDataContainer localSetting = ApplicationData.Current.LocalSettings;
private void Button_Click(object sender, RoutedEventArgs e)
{
isoSetting.Add(firstKey, true);
localSetting.Values[secondKey] = false;
//isoSetting.Save(); // IsolatedStorageSettings have to be saved
Debug.WriteLine("Is first key in LocalSettings: {0}", localSetting.Values.ContainsKey(firstKey));
Debug.WriteLine("Is first key in ApplicationSettings: {0}", isoSetting.Contains(firstKey));
Debug.WriteLine("Is second key in LocalSettings: {0}", localSetting.Values.ContainsKey(secondKey));
Debug.WriteLine("Is second key in ApplicationSettings: {0}", isoSetting.Contains(secondKey));
}
private void Button_Click2(object sender, RoutedEventArgs e)
{
// run this button after app restart without clicking first button
// and saving IsoSettings
Debug.WriteLine("Is first key in LocalSettings: {0}", localSetting.Values.ContainsKey(firstKey));
Debug.WriteLine("Is first key in ApplicationSettings: {0}", isoSetting.Contains(firstKey));
Debug.WriteLine("Is second key in LocalSettings: {0}", localSetting.Values.ContainsKey(secondKey));
Debug.WriteLine("Is second key in ApplicationSettings: {0}", isoSetting.Contains(secondKey));
}
如果我正在编写一个新的应用程序,那么我将使用新的 ApplicationData.LocalSettings API - 它更新,将来将这样的应用程序移植到RunTime将会容易得多,因为WP8.1 RT不支持 IsolatedStorageSettings 。