Search code examples
xamarin.formsxamarin.androidxamarin.iosuicollectionviewcollectionview

CollecionView RemainingItemThresholdReached is not firing when Tabbed Pages are initialized in Xamarin iOS


I am stuck with this annoying problem in iOS(works perfectly fine in Android) and I can't seem to find a solution at all. Could someone please help me? Thanks.

I have tabbed pages in which I have a Message Tab which consists of a collection view which shows the user messages. When the app starts I download about 5 messages and then wait for the remainingitemthresholdreached to fire so I can go ahead and fetch more data but unfortunately, it doesn't fire and I am stuck with the initial 5 messages.

XAML

                <CollectionView Grid.Row="1" ItemsSource="{Binding AllMessages, Mode=TwoWay}"  x:Name="myMessagesCV" SelectionMode="Single" SelectionChanged="MyMessagesCV_SelectionChanged" RemainingItemsThresholdReached="MyMessagesCV_RemainingItemsThresholdReached" RemainingItemsThreshold="5">
            <CollectionView.ItemTemplate>
                <DataTemplate>
                    // Some Code here
                </DataTemplate>
            </CollectionView.ItemTemplate>
        </CollectionView>

Code Behind

    private void MyMessagesCV_RemainingItemsThresholdReached(object sender, EventArgs e)
    {
        if (IsBusy)
            return;

        IsBusy = true;

        if (!LoadedAllMyMessages)
        {
            GetMyMessages();
        }

        if (LoadedAllMyMessages)
        {
            myMessagesCV.RemainingItemsThreshold = -1;
        }
    }

Please someone save me. Cheers guys!


Solution

  • The RemainingItemsThresholdReached could be triggered with enough items.

    You could check it in IncrementalLoadingPage of Scrolling. Or you could use the RemainingItemsThresholdReachedCommand

    Here is the example for yoru reference. https://github.com/xamarin/xamarin-forms-samples/tree/master/UserInterface/CollectionViewDemos