Hello,
===================Update====================
but if you do not use the "HeightRequest" property, the list does not scroll, how to fix this?
You can replace the VerticalStackLayout with a Grid. See this tip from Collectionview document
Firstly, please donot use ScrollView as the rootView, if you set it as rootView, Collectionview's Scroll Event will not execute and set a specific value for Collectionview's HeightRequest property.
I add the Scrolled event for Collectionview and set the rootview to the stacklayout like following code.
_collection = new CollectionView
{
EmptyView = "Persons empty",
RemainingItemsThreshold = 5,
HeightRequest = 200,
};
...
_collection.Scrolled += _collection_Scrolled;
_content.Add(_collection);
Content = _content ;
Next, you can get all of appeared Person objects by FirstVisibleItemIndex and LastVisibleItemIndex.
private void _collection_Scrolled(object? sender, ItemsViewScrolledEventArgs e)
{
var FirstIndex = e.FirstVisibleItemIndex;
var LastIndex = e.LastVisibleItemIndex;
for (var i = FirstIndex; i <= LastIndex; i++) {
//get all of appeared Person objects
Person appearPerson = _persons[i];
}
}
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.