简体   繁体   中英

ListPicker TwoWay Binding and itemsource

I try to build settings page to my Windows Phone 8 app, the settings page has couple of ListPickers. The basic idea has been taken from here: http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff769510(v=vs.105).aspx

In my settings page xaml I have just declared:

<toolkit:ListPicker x:Name="listPicker1" ExpansionMode="FullScreenOnly" SelectionMode="Single" FullModeItemTemplate="{StaticResource generalListPickerFullTemplate}" ItemTemplate="{StaticResource generalListPickerTemplate}" SelectedItem="{Binding Source={StaticResource appSettings}, Path=listPicker1, Mode=TwoWay}" />

In "code behind", I create list and set it item source to listPicker1

listPicker1List.Add(new ListPickerItem() { name = "First value", value = "value_1" });
listPicker1List.Add(new ListPickerItem() { name = "Second value", value = "value_2" });
this.listPicker1.ItemsSource = listPicker1List;

StaticResource appSettings points to class which is basically similar than in the MS example,

public ListPickerItem listPicker1
{
    get
    {
        return GetValueOrDefault<ListPickerItem>(KeyName, Default);
    }

    set
    {
        if (AddOrUpdateValue(KeyName, value))
        {
            Save();
        }
    }
}

So is it not possible to set itemsource and use two way bindig? If I set these both, I get System.ArgumentOutOfRangeException .

Basically my only goal is to have listPicker with items, which have text to display for user and value. And to easily set and get these to Isolates storage.

设置itemsource或选择一个项目时出现此错误?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM