0

10 ページすべてで使用される変数があります。すべてのページからアクセスできるようにするには、どこに保存すればよいですか? に変数を保存することで、iOS でも同じタスクを実行できますAPPDELEGATE。Windows phone での解決策は何ですか?

4

2 に答える 2

0

あなたは助けるためにいくつかの背景を読むべきです

IsolatedStorageSettings のサンプル コード

public class AppSettings
    {
        // Our settings
        IsolatedStorageSettings settings;

        // The key names of our settings
        const List<String> PropertyIdList           = null;
        const List<String> FavPropertyIdList        = null;
        const string SearchSource                   = null;
        const string[] Suggestions                  = null;
        const string PropertyId                     = null;
        const string AgentContactInfo               = null;
        const string AgentShowPhoto                 = null;

        /// <summary>
        /// Constructor that gets the application settings. 
        /// </summary>
        public AppSettings()
        {
            // Get the settings for this application.
            settings = IsolatedStorageSettings.ApplicationSettings;
        }

        /// <summary>
        /// Update a setting value for our application. If the setting does not
        /// exist, then add the setting.
        /// </summary>
        /// <param name="Key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool AddOrUpdateValue(string Key, Object value)
        {
            bool valueChanged = false;

            // If the key exists
            if (settings.Contains(Key))
            {
                // If the value has changed
                if (settings[Key] != value)
                {
                    // Store the new value
                    settings[Key] = value;
                    valueChanged = true;
                }
            }
            // Otherwise create the key.
            else
            {
                settings.Add(Key, value);
                valueChanged = true;
            }
            return valueChanged;
        }

        /// <summary>
        /// Get the current value of the setting, or if it is not found, set the 
        /// setting to the default setting.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="Key"></param>
        /// <param name="defaultValue"></param>
        /// <returns></returns>
        public T GetValueOrDefault<T>(string Key, T defaultValue)
        {
            T value;

            // If the key exists, retrieve the value.
            if (settings.Contains(Key))
            {
                value = (T)settings[Key];
            }
            // Otherwise, use the default value.
            else
            {
                value = defaultValue;
            }
            return value;
        }
    }
于 2013-10-30T09:33:18.410 に答える