2
votes

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));
        }
    }
}
2

2 Answers

1
votes

I reproduced your code and got the same issue. Just by dropping Style="{StaticResource PhoneTextLargeStyle}" from

<DataTemplate>
<TextBlock Text="{Binding}" Margin="24,0,0,0" />
</DataTemplate>

looks like it solves the problem. however is a weird behavior which its source comes from Style property.

I'm gonna try out other possibilities and will let you know if I would find out some other info.

Regards,

1
votes

I have submitted a patch to the project http://www.codeplex.com/Download?ProjectName=silverlight&DownloadId=375366 described as follows:

There is a race condition when navigating to the full picker page, where the items that had their RotationX property animated to spin them in may have moved off the screen before the UpdateOutOfViewItems delegate is called.

As a result some items can remain with a RotationX of -90.

My solution is to pass in the list of items that were in view to the UpdateOutOfView items when the animations were created, rather than collecting those visible when the delegate is finally run.

http://www.codeplex.com/Download?ProjectName=silverlight&DownloadId=375366 is the updated ListPickerPage.xaml.cs file required to fix the bug.