I have a project that requires binding a list of strings to a listpicker control. When the binding is done (either in Loaded or OnNavigatedTo events), the listpicker opens to show the bound items, but some items are randomly missing (in fullscreen mode). When the listpicker starts closing, the missing items seem to appear. Not sure why this is happening - is it a listpicker bug or am I binding incorrectly?. I am using the November 2011 release of the silverlight toolkit.
PS: The issue does not seem to happen when using a small number of items (say up to 10)
Please use the below code to recreate the issue
Main page XAML
<TextBlock Text="Time of Day" Grid.Row="0" Margin="12,0,0,0" Style="{StaticResource PhoneTextNormalStyle}" />
<toolkit:ListPicker x:Name="TimesOfDayList" Grid.Row="1" SelectionMode="Multiple" FullModeHeader="Time of Day"
ExpansionMode="FullScreenOnly" ItemsSource="{Binding TimesOfDay}"
Margin="12,0,12,12">
<toolkit:ListPicker.FullModeItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" Margin="24,0,0,0" Style="{StaticResource PhoneTextLargeStyle}" />
</DataTemplate>
</toolkit:ListPicker.FullModeItemTemplate>
</toolkit:ListPicker>
</Grid>
Main page code behind
private MainPageViewModel _viewModel;
public MainPage()
{
InitializeComponent();
Loaded += MainPage_Loaded;
TimesOfDayList.SummaryForSelectedItemsDelegate = TimesOfDaySummary;
}
void MainPage_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
_viewModel = new MainPageViewModel();
DataContext = _viewModel;
}
private string TimesOfDaySummary(IList items)
{
string itemNames = string.Empty;
if (items != null && items.Count > 0)
{
var itemsList = items.Cast<string>().AsQueryable();
foreach (var item in itemsList)
{
if (item != itemsList.Last())
itemNames += item + ", ";
else
itemNames += item;
}
}
return itemNames;
}
Viewmodel class
public class MainPageViewModel : INotifyPropertyChanged
{
public MainPageViewModel()
{
TimesOfDay = new List<string>
{
"12:00 AM",
"12:30 AM",
"01:00 AM",
"01:30 AM",
"02:00 AM",
"02:30 AM",
"03:00 AM",
"03:30 AM",
"04:00 AM",
"04:30 AM",
"05:00 AM",
"05:30 AM",
"06:00 AM",
"06:30 AM",
"07:00 AM",
"07:30 AM",
"08:00 AM",
"08:30 AM",
"09:00 AM",
"09:30 AM",
"10:00 AM",
"10:30 AM",
"11:00 AM",
"11:30 AM",
"12:00 PM",
"12:30 PM",
"01:00 PM",
"01:30 PM",
"02:00 PM",
"02:30 PM",
"03:00 PM",
"03:30 PM",
"04:00 PM",
"04:30 PM",
"05:00 PM",
"05:30 PM",
"06:00 PM",
"06:30 PM",
"07:00 PM",
"07:30 PM",
"08:00 PM",
"08:30 PM",
"09:00 PM",
"09:30 PM",
"10:00 PM",
"10:30 PM",
"11:00 PM",
"11:30 PM"
};
}
private List<string> _timesOfDay;
public List<string> TimesOfDay
{
get { return _timesOfDay; }
set
{
if(_timesOfDay != value)
{
_timesOfDay = value;
OnPropertyChanged("TimesOfDay");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string property)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(property));
}
}
}