Recently I was using LongListMultiSelector(LLMS) in WPToolkit and now facing a quite strange bug. That is, when the ItemsSource of the LLMS has exactly 3 items. Then the second one's view doesn't get refreshed, while the other two do. And the LLMS is all right when the count is other than 3. I wrote a small App to test the situation. In this test, a LLMS is binding to an ObservableCollection<ItemViewModel>. Here is the code of ItemViewModel:
public class ItemViewModel : INotifyPropertyChanged
{
public ItemViewModel()
{
time = DateTime.Now;
}
private DateTime _time;
/// <summary>
/// Property for test use
/// </summary>
public DateTime time
{
get { return _time; }
set
{
if (_time != value)
{
_time = value;
RaisePropertyChanged("time");
}
}
}
#region INPC Impl
public event PropertyChangedEventHandler PropertyChanged;
private void RaisePropertyChanged(string pName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(pName));
}
#endregion
}
And my LLMS is set like this:
<phone:PhoneApplicationPage.Resources>
<local:ItemToStrConverter x:Key="cvt"></local:ItemToStrConverter>
</phone:PhoneApplicationPage.Resources>
......
<toolkit:LongListMultiSelector Height="300" Name="llms">
<toolkit:LongListMultiSelector.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Converter={StaticResource cvt}}"
Style="{StaticResource PhoneTextLargeStyle}"></TextBlock>
</DataTemplate>
</toolkit:LongListMultiSelector.ItemTemplate>
</toolkit:LongListMultiSelector>
The ItemToStrConverter is something that converts an instance of ItemViewModel to string (time.ToString()).
Please do notice that the Text of TextBlock in the DataTemplate is not binding to time. Instead, it is binding to the ItemViewModel instance directly.
So let's say if the LLMS is on the MainPage, and I go to some other pages to modify an ItemViewModel instance's time and go back to MainPage, this will cause the LLMS to be loaded and new one or more ItemToStrConverter to convert. If I have more or less than 3 items, everything is fine, all the instances will be converted properly. However, when I have 3 items, the second one does not get converted. I made a breakpoint in the Convert method, and the bug is occuring because this method was only called twice (to the 1st and 3rd instance). It seems that the LLMS simply ignores the 2nd instance.
Has anybody met this problem before?