2

我正在构建一个 Windows Phone 8.1 Silverlight 应用程序。我可以使用以下两个注册表:

Windows.Storage.ApplicationData.Current.LocalSettings;

IsolatedStorageSettings.ApplicationSettings;
  1. 这两者有什么区别?
  2. 哪一个更好?
4

2 回答 2

0

使用这两种设置有很大的不同:

所以它们是完全不同的东西,如果您将密钥添加到上述设置之一,那么它不会在第二个自动出现。考虑两个按钮:

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

于 2015-01-02T14:01:33.410 回答
0

Windows.Storage.ApplicationData.Current.LocalSettings和之间的区别在于IsolatedStorageSettings.ApplicationSettings,第一个是较新的统一 Windows Store App API,而后者来自“旧”Silverlight API。

新的并不总是更好,但我个人认为你应该在这里使用现代版本。两者都适用于 Silverlight,但如果您必须将代码迁移到 WinRT,您将节省一些时间,因为IsolatedStorageSettingsAPI 在 WinRT 下不起作用。

于 2015-01-02T13:07:57.890 回答