1

我正在开发一个从 Web 服务获取数据并显示它的 Windows Phone 8 应用程序。

我有一个绑定到 LongListSelector 的通知列表,当用户滚动到末尾时,我想在其中显示更多项目:一个无限列表。

我搜索了很多,但在我的案例中没有找到任何解决方案,它们都在谈论模型、视图、视图模型架构。如果我将列表更改为 ObservableCollections,我必须重复很多工作。

我的实际代码是:

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);
        }
    }
}

元素已添加到列表中但未显示,是否有任何解决方案可以在将新项目添加到 LongListSelector 后立即显示它们?

4

1 回答 1

1

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.

于 2014-01-27T14:20:03.960 回答