I am having an issue when trying to bind an object I created to a listpicker. I have had success using a listpicker with strings and ints but I am running into issues when trying to use my own class/object.
Here is the XML (I have two listpickers, one works and one doesn't)
<toolkit:ListPicker
x:Name="CountryListPicker"
Margin="0,2,0,10" Width="458"
BorderThickness="3" FullModeHeader="Country"
CacheMode="BitmapCache">
<toolkit:ListPicker.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Border Background="LightBlue" Width="34" Height="34">
<TextBlock Text="{Binding _code}" FontSize="16" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<TextBlock Text="{Binding _name}" Margin="12 0 0 0"/>
</StackPanel>
</DataTemplate>
</toolkit:ListPicker.ItemTemplate>
<toolkit:ListPicker.FullModeItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0 21 0 20">
<TextBlock Text="{Binding _name}" Margin="16 0 0 0" FontSize="43" FontFamily="{StaticResource PhoneFontFamilyLight}"/>
</StackPanel>
</DataTemplate>
</toolkit:ListPicker.FullModeItemTemplate>
</toolkit:ListPicker>
<toolkit:ListPicker
x:Name="testPicker"
Header="Accent color"
FullModeHeader="ACCENTS"
CacheMode="BitmapCache">
<toolkit:ListPicker.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding}" Margin="12 0 0 0"/>
</StackPanel>
</DataTemplate>
</toolkit:ListPicker.ItemTemplate>
<toolkit:ListPicker.FullModeItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0 21 0 20">
<TextBlock Text="{Binding}"
Margin="16 0 0 0"
FontSize="43"
FontFamily="{StaticResource PhoneFontFamilyLight}"/>
</StackPanel>
</DataTemplate>
</toolkit:ListPicker.FullModeItemTemplate>
</toolkit:ListPicker>`
The first list picker is my new object binding one and the second is binding a string.
Here is the code behind:
ObservableCollection<Country> countries = new ObservableCollection<Country>();
countries.Add(new Country { _code = "US", _name = "United States1"});
countries.Add(new Country { _code = "US", _name = "United States2" });
countries.Add(new Country { _code = "US", _name = "United States3" });
countries.Add(new Country { _code = "US", _name = "United States4" });
countries.Add(new Country { _code = "US", _name = "United States5" });
countries.Add(new Country { _code = "US", _name = "United States6" });
this.CountryListPicker.ItemsSource = new ReadOnlyCollection<Country>(countries);
ObservableCollection<string> _accentColors = new ObservableCollection<string>();
_accentColors.Add("Blue");
_accentColors.Add("Blue2");
_accentColors.Add("Blue3");
_accentColors.Add("Blue4");
_accentColors.Add("Blue5");
_accentColors.Add("Blue6");
_accentColors.Add("Blue7");
this.testPicker.ItemsSource = new ReadOnlyCollection<string>(_accentColors);
The 2nd listpicker is fine and I think this is because it contains strings.
My broken listpicker displays all of the correct data but when I select a listpickeritem, it doesn't select it. The app loads the full listpicker and I click one of the items and when I return back to the main view the selected item isn't reflected in the listpicker.
Anyone have any ideas? Need me to explain anymore?
ListPicker
, you might wanna go check it out. :) silverlight.codeplex.com/releases/view/75888 – Justin XLListPicker
gets loaded again and resets itsItemsSource
and that's why it loses itsSelectedIndex
. – Justin XL