This project has moved. For the latest updates, please go here.

LongListSelector + BatchObservableCollection

Aug 11, 2011 at 12:16 PM
Edited Aug 11, 2011 at 2:37 PM

I'm using a LongListSelector bound to an BatchObservableCollection, which sometimes results in a weird behaviour:

1. When navigating to a page with a LongListSelector that binds to an BatchObservableCollection property of a ModelItem that was just Refreshed (Refresh()) on a previous page, LongListSelector displays nothing (e.g. initially; when scrolled up a bit - a few pixels - the whole list appears correctly rendered).

2. When trying to trick the LongListSelector to rebind by setting it's DataContext to null and then to the original ViewModel, a NullReferenceException is thrown (at Microsoft.Phone.Controls.LongListSelector.Balance()   at Microsoft.Phone.Controls.LongListSelector.LongListSelector_LayoutUpdated(Object sender, EventArgs e)   at System.Windows.FrameworkElement.OnLayoutUpdated(Object sender, EventArgs e)   at MS.Internal.JoltHelper.RaiseEvent(IntPtr target, UInt32 eventId, IntPtr coreEventArgs, UInt32 eventArgsTypeIndex)).

The exception is thrown only when the time between the Refresh() and rebind is short (as if BatchObservableCollection is still populating?)

And the question raised is does it even makes sense to use a LongListSelector with BatchObservableCollection at all, since the LongListSelector would take care of partial loading anyway? Should there be any other benefits from using BatchObservableCollection or should I just go with plain old ObservableCollection?

UPDATE: at first it appeared that this behavior is happening only with BatchObservableCollection, but further testing proved that using ObservableCollection isn't any better.

Thanks!

Aug 11, 2011 at 9:46 PM
Edited Aug 11, 2011 at 9:47 PM

UPDATE 2: seems this is actually a bug in LLS :( Documented with this WP7 toolkit work item: http://silverlight.codeplex.com/workitem/8376 

Coordinator
Aug 17, 2011 at 3:02 AM

OK, thanks for updating!