2

Windows Phone 8.1 Silverlight アプリを構築しています。次のレジストリの両方を使用できます。

Windows.Storage.ApplicationData.Current.LocalSettings;

IsolatedStorageSettings.ApplicationSettings;
  1. これら2つの違いは何ですか?
  2. どちらの方がよいですか?
4

2 に答える 2

0

両方の設定を使用すると、大きな違いがあります。

したがって、それらはまったく別のものであり、上記のいずれかの設定にキーを追加すると、秒単位で自動的に表示されません。次の 2 つのボタンを検討してください。

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 を使用します。WP8.1 RT はIsolatedStorageSettingsをサポートしていないため、この API はより新しく、将来的にそのようなアプリを RunTime に移植するのがはるかに簡単になります。

于 2015-01-02T14:01:33.410 に答える
0

Windows.Storage.ApplicationData.Current.LocalSettingsとの違いはIsolatedStorageSettings.ApplicationSettings、前者が新しい統合 Windows ストア アプリ API であるのに対し、後者は「古い」Silverlight API からのものであることです。

新しいものが常に良いとは限りませんが、個人的には、ここでは最新バージョンを使用する必要があると思います. どちらも Silverlight で動作しますが、コードを WinRT に移行する必要がある場合は、IsolatedStorageSettingsAPI が WinRT では動作しないため、時間を節約できます。

于 2015-01-02T13:07:57.890 に答える