首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在设置页面中设置列表选择器,并从IsolatedStorageSettings中存储和检索值?(内页说明)

问如何在设置页面中设置列表选择器,并从IsolatedStorageSettings中存储和检索值?(内页说明)
EN

Stack Overflow用户
提问于 2013-02-01 14:22:28
回答 1查看 353关注 0票数 3

我不明白为什么我在列表选择器和将值保存到IsolatedStorageSettings时出错了,

我试过了,

Settings.cs

代码语言:javascript
复制
    // Our isolated storage settings
    IsolatedStorageSettings isolatedStore;

    // The isolated storage key names of our settings
    const string ListPickerSettingKeyName = "ListPickerSetting";

    // The default value of our settings
    const int ListPickerSettingDefault = 0;

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

        }
        catch (Exception e)
        {
            Debug.WriteLine("Exception while using IsolatedStorageSettings: " + e.ToString());
        }
    }

    /// <summary>
    /// Property to get and set a ListPicker Setting Key.
    /// </summary>
    public int ListPickerSetting
    {
        get
        {
            return GetValueOrDefault<int>(ListPickerSettingKeyName, ListPickerSettingDefault);
        }
        set
        {
            AddOrUpdateValue(ListPickerSettingKeyName, value);
            Save();
        }
    }

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

        // If the key exists, retrieve the value.
        if (isolatedStore.Contains(Key))
        {
            value = (valueType)isolatedStore[Key];
        }
        // Otherwise, use the default value.
        else
        {
            value = defaultValue;
        }

        return value;
    }


    /// <summary>
    /// Save the settings.
    /// </summary>
    public void Save()
    {
        isolatedStore.Save();
    }

在我的MainPage.xaml中

代码语言:javascript
复制
    <toolkit:ListPicker Name="lstSetting" SelectionMode="Single" Foreground="DarkBlue" SelectedIndex="{Binding Source={StaticResource Settings}, Path=ListPickerSetting, Mode=TwoWay}" >
                        <toolkit:ListPickerItem Content="item1" />
                        <toolkit:ListPickerItem Content="item2" />
                    </toolkit:ListPicker>

实际问题是当所选索引为1时不显示item2,

请告诉我如何在所选索引中显示所选项目。。。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-06 23:10:03

看起来路径与属性名不匹配。Path=Setting不应该是Path=ListPickerSetting吗?

此外,设置需要实现INotifyPropertyChanged,以便当属性更改时,控件将知道它需要获取新值。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14640867

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档