I need to implement endless listbox (the one that is loading chunks of data when user scroll to the end) and I am using ViewModel.
I have ListBox bound to ObservableCollection, but I don’t known how to get notified about reaching the end of it and yet not to break the MVVM paradigm.
How can I achieve this?
The only thing I need to know is how to retain MVVM features and constraints and yet to get notified when the collection has been enumerated to it’s end.
Thanks.
EDIT
I have been digging around a little and I am afraid that this is not an easy solution. I think the only possibility is to implement custom collection which will implement ICollection and INotifyCollectionChanged. But I don’t know how the internal mechanisms of ListBox and other ItemsSource enabled controls work so I don’t know how to implement lazy loading.
Is the primary fetching mechanism of WP controls which utilize ItemsSource the IEnumerable interface? Or does it use indexer methods? How does it call count? Does it depend on count or can it be changed during it’s lifecicle (and in which calls? I think that not all calls can change the Count and then call NotifyCollectionChanged).
Is there any documentation? Or is there any implementation available?
I found a nice solution that does not break MVVM and yet supplies quite elegant solution to this problem (it seems on the first look, I haven’t investigated it properly yet.)
Look at http://danielvaughan.orpius.com/post/Scroll-Based-Data-Loading-in-Windows-Phone-7.aspx
There’s also stackoverflow topic for that, which I overlooked. Look at WP7 Auto Grow ListBox upon reaching the last item.