Aug 11, 2011 at 11:16 AM
Edited Aug 11, 2011 at 1: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.