使用增量加载在 Xamarin.Forms ListView/CollectionView 上加载分组集合的最佳方式

Best way to load a grouped collection on Xamarin.Forms ListView/CollectionView with incremental loading

使用增量加载在 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 或 [=17= 中的最佳方式(或最佳实践)是什么? ]?

为了加载分组集合,我将一些附加数据添加到 ItemsSource 中,例如:

    PersonViewModel pvm = new PersonViewModel();
           private  ObservableCollection<PersonGroup> myitems = new ObservableCollection<PersonGroup>();
            public TestGroup()
            {
    
                InitializeComponent();
                myitems = pvm.Persons;
                //set collectionview
                mycol.ItemsSource =myitems;
                mycol.RemainingItemsThreshold = 2;
                mycol.RemainingItemsThresholdReached += Mycol_RemainingItemsThresholdReached;
            }
    
            private void Mycol_RemainingItemsThresholdReached(object sender, EventArgs e)
            {
               
                for (int i = 0; i <= 3; i++)
                {
                    myitems.Add(new PersonGroup("plusgroup", new List<Person> { new 
                    Person { name="plus1",
                    address="11111"},
                   new Person { name="plus2",
                    address="22222"}
    
                     }));
                }
            }

这是我的视图模型和模型:

public class PersonViewModel {


    public ObservableCollection<PersonGroup> Persons { get; set; } = new ObservableCollection<PersonGroup>();

    public List<Person> peoplelist = new List<Person>();

    public PersonViewModel()

    {

        for (int k = 1; k <= 3; k++)

        {

           peoplelist.Add(new Person
            {
                name = "People" + k.ToString(),

                address = "somewhere"+k.ToString()
            });

        }


        for (int i = 1; i < 50; i++)

        {

            Persons.Add(new PersonGroup("Group" + i.ToString(), peoplelist));

        }

    }
}

型号:

public class PersonGroup{
    public string GroupName { set; get; }
    
            public  PersonGroup(string name,List<Person>persons):base(persons)
            {
                GroupName = name;
            }
    
        }

结果: