【发布时间】:2021-08-12 09:39:19
【问题描述】:
使用增量加载在 Xamarin.Forms ListView/CollectionView 上加载分组集合的最佳方式是什么?
例如,假设一个集合包含多个组,每个组包含一个项目列表。
[
[123, 143, 341234, 234234, 514232, 23511, 673456, ...],
[12, 143, 341234, 234234, 514232, 23511, , ...],
[12, 143, 341234, 234234, 514232, 23511, 313, ...],
[12, 143, 341234, 514232, 23511, 673456, ...],
[12, 143, 341234, 234234, 514232, 132, 23511, 673456, ...],
.
.
.
[12, 143, 341234, 234234, 514232, 23511, 673456, ...],
]
更新
使用一维列表,我可以使用 ListView.ItemAppearing/CollectionView.RemainingItemsThresholdReached 事件将数据加载到 ListView 或 CollectionView 中。
Infinite Scroll with Xamarin.Forms CollectionView
Load More Items at End of ListView in Xamarin.Forms
listView.ItemAppearing += ListView_ItemAppearing;
IList<Item> originalList = new List<Item> {Item1, ..., Item10000};
private void ListView_ItemAppearing(object sender, ItemVisibilityEventArgs e)
{
if (// all the items in the original list loaded into the listview)
{
listView.ItemAppearing -= ListView_ItemAppearing;
}
else
{
// Add next set of items from the original list to the listview
}
}
所以我担心的是,将分组集合增量加载到ListView 或CollectionView 中的最佳方式(或最佳实践)是什么?
【问题讨论】:
-
请参考这个问题stackoverflow.com/questions/58366576/…这将回答你的问题。
-
@AdrainZhu-MSFT 我不想无限滚动列表。很抱歉造成误解,我已经更新了问题。
-
您可以设置一个列表(A)包含您要显示的对象的列表。并将新列表添加到 ListView.ItemAppearing/CollectionView.RemainingItemsThresholdReached 事件中的列表(A)中。
标签: xamarin xamarin.forms xamarin.forms.listview xamarin.forms.collectionview