How to get first and last item visible in MAUI CollectionView - Stack Overflow

admin2025-04-19  0

Using Maui.Controls 9.0.40, primarily for iOS 17.5 and 18.3.

I want to know what range of items are CURRENTLY DISPLAYED (that, is visible to the user). This will typically be about 20 items (out of about 500).

It seems like it should be easier than what I've got.

   <CollectionView
      ...
      Scrolled="histDataList_Scrolled"
      >

and

private void myCollectionView_Scrolled(object sender, ItemsViewScrolledEventArgs e) {
    firstVisItem = e.FirstVisibleItemIndex;
    lastVisItem = e.LastVisibleItemIndex;
}

oh, and since the Scrolled event is not called when opened, I've added this crasiness when opened:

   myCollectionView.ScrollTo(1);
   myCollectionView.ScrollTo(0);

I can have up to 1000 items, and I'm trying to offer "select all that are visible", cuz otherwise it's pretty tiresome. What I'm doing can't be the "right" way, is it?

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745077934a283678.html

最新回复(0)