Friday, 4 May 2012

One of our ListItems is missing! ListPicker Bug Alert!

I used the November ‘11 Silverlight Toolkit ListPicker control in one of my upcoming WP7 apps, and was surprised when impatiently, I started scrolling down while my full screen picker page was opening.

Unfortunately, when I got to the bottom of the page, some of the items were not visible, though vertical space was reserved for them.

Off to the source I went, and discovered that the ListPicker control initially sets every item on the page to be have a PlaneProjection with a RotationX of –90.  That would at least explain why my items weren’t visible.  They were rotated away from the field of view so they couldn’t be seen (Just like Calvin and Hobbes in 2D form)

So how did it happen?

Deep inside the ListPickerPage.xaml.cs file, in the UpdateVisualState function, there’s an IList<WeakReference> itemsInView that holds the list of items currently in view, then a few lines later, a Dispatcher.BeginInvoke on UpdateOutOfViewItems.

UpdateOutOfViewItems then collects the list of visible items again.  Only they might not be the same items.  In fact, any items that are new to the set will not be drawn correctly.

The Solution

The solution of course is to change the call to pass in the list of in-view items to the UpdateOutOfViewItems, changing the call to

Dispatcher.BeginInvoke(new Action(() => UpdateOutOfViewItems(itemsInView)));

and the signature to:

private void UpdateOutOfViewItems(IList<WeakReference> itemsInView)

and finally we don’t call GetItemsInViewPort in the UpdateOutOfViewItems.

I’ve added this fix as a hotfix to the SilverlightToolkit project here:


No comments:

Post a Comment