Reputation: 112
I'm developing a Windows Phone 8 application that gets data from a Webservice and displays it.
I have a list of notifications bound to a LongListSelector, in which I want to display more items when the user scrolls to the end : an infinite list.
I searched a lot but I haven't found any solution in my case, they all speak about Model, View, ViewModel architecture. I have to repeat a lot of my work if I will change my Lists to ObservableCollections.
My actual code is:
private async void NotificationList_ItemRealized(object sender, ItemRealizationEventArgs e)
{
if (NotificationList.ItemsSource == null) return;
int currentItemsCount = NotificationList.ItemsSource.Count;
if (currentItemsCount >= _offsetKnob && e.Container != null)
{
var list = await LoadDataAsync(++page);
foreach (var notification in list)
{
NotificationList.ItemsSource.Add(notification);
}
}
}
The elements are added to the list but not displayed, is there any solution to display the new items as soon as they get added to the LongListSelector ??
Upvotes: 1
Views: 297
Reputation: 354
Why is changing from Lists to ObservableCollections difficult for you? ObservableCollection is the right way to go when your list is getting updated in the background and you want to notify the UI on the updates. I have written 2 samples on incremental loading data from a web service(500px in the sample).
Windows Phone Series – Incremental Loading multiple data sources inside a Pivot
Windows Phone Series – Incremental Loading
If you do not want to change to ObservableCollection, then you would have to update the UI binding manually.
Upvotes: 1