Im trying to implement a lazy "load more" items when the user gets to the bottom of the listbox, but everytime i try to add new items to the listbox i get results like this:
"Operation not supported on read-only collection."
I've already tried several solutions from forums to blogs none seem to work. I can't even understand the logic behinds the problem which seems a bit odd for me.
What i'm doing is basically loading a list of items and assigning as the itemsource of my listbox.
wineFilterListBox.ItemsSource = wines;
When the user gets to the bottom of the list, i add more items (just like twitter app for wp7)
public ObservableCollection<Wine> wines;
...
if (atBottom)
{
int Count = page.wineFilterListBox.Items.Count;
int end = Count + 10;
for (int i = Count; i < end; i++)
{
page.LoadWineList(Count);
}
}
...
private void LoadWineList(int Count = 1)
{
...
wineFilterListBox.Items.Add(wines);
}
When you use ItemSource
the Items
collection becomes read-only. It sounds like you'd have to add the data to the collection instead of to the ListBox
Items
property.
See the MSDN: ItemsControl.ItemSource Property
In particular, this section:
When the ItemsSource property is set, the Items collection is made read-only and fixed-size.
Try adding the item to the wines
collection directly, since your collection is an `ObservableCollection':
You should set the ItemsSource to an object that implements the INotifyCollectionChanged interface so that changes in the collection will be reflected in the ItemsControl. The ObservableCollection(Of T) class defines such an object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With