It's not working on UWP but It's working on Android.
Triggering the binded command.
Nothing is happened.
I have written myself a temp workaround for this.
First, in the Collection View XAML add Scrolled event handler
<CollectionView ...
...
Scrolled="CollectionView_OnScrolled">
Then in code behind:
private void CollectionView_OnScrolled(object sender, ItemsViewScrolledEventArgs e)
{
if (Device.RuntimePlatform != Device.UWP)
{
return;
}
if (sender is CollectionView cv)
{
var count = cv.ItemsSource.Cast<ICollection>().Sum(c => c.Count);
if (e.LastVisibleItemIndex + 1 - count + cv.RemainingItemsThreshold >= 0)
{
if (cv.RemainingItemsThresholdReachedCommand.CanExecute(null))
cv.RemainingItemsThresholdReachedCommand.Execute(null);
}
}
}
I have written myself a temp workaround for this.
First, in the Collection View XAML add Scrolled event handler
<CollectionView ... ... Scrolled="CollectionView_OnScrolled">
Then in code behind:
private void CollectionView_OnScrolled(object sender, ItemsViewScrolledEventArgs e) { if (Device.RuntimePlatform != Device.UWP) { return; } if (sender is CollectionView cv) { var count = cv.ItemsSource.Cast<ICollection>().Sum(c => c.Count); if (e.LastVisibleItemIndex + 1 - count + cv.RemainingItemsThreshold >= 0) { if (cv.RemainingItemsThresholdReachedCommand.CanExecute(null)) cv.RemainingItemsThresholdReachedCommand.Execute(null); } } }
I've tried to use your workaround to make my infinitescroll work, changing the reacheadcommand to my Reached method but I had 2 problems:
Is "(cv.ItemsSource as ICollection).Count" the same as "cv.ItemsSource.Cast().Sum(c => c.Count)"? And LastVisibleItemIndex won't update for me after updating the collectionview collection
The code from @artur170dx worked for me. (Almost)
As the items are cached, I needed a trick to get the logical children count instead of itemsource count.
if (sender is CollectionView cv && cv is IElementController element)
{
var count = element.LogicalChildren.Count;
if (e.LastVisibleItemIndex + 1 - count + cv.RemainingItemsThreshold >= 0)
{
if (cv.RemainingItemsThresholdReachedCommand.CanExecute(null))
cv.RemainingItemsThresholdReachedCommand.Execute(null);
}
}
Most helpful comment