xamarin.formsscrollviewexpander

Xamarin Forms: How to detect the scrollview(or expander) end or top reached?


I need to load more data when scrollview reaches the end or top. I found the same thread over here, but on that, I didn't understand what is MyScrollView.

private void OnScrolled(object sender, ScrolledEventArgs e)
{
    MyScrollView scrollView = sender as MyScrollView;
    double scrollingSpace = scrollView.ContentSize.Height - scrollView.Height;

    if (scrollingSpace <= e.ScrollY)
    {
       //reached end
    }
}

I implemented the same in ListView using the ItemAppearing event. But currently, I am using Expander on the UI to display data. Is there any same kind of event for the expander to reach the end and beginning? The expander is inside of a scrollview, that's why I started researching about the scrollview end event.

How can I trigger some kind of event when scrollview reaches end or beginning?

Update

My scrollview contents are like below, it contains BindableLayout and Expander.

<ScrollView
    x:Name="MyScrollView"
    Scrolled="OnScrolled">
    <StackLayout BindableLayout.ItemsSource="{Binding AllItems,Mode=TwoWay}">
        <BindableLayout.ItemTemplate>
            <DataTemplate>
                <Expander>
                </Expander>
            </DataTemplate>
        </BindableLayout.ItemTemplate>
    </StackLayout>
</ScrollView>

Solution

  • Like I mentioned in the question I have implemented the same feature in ListView using the ItemAppearing event. But in this case, my data is a list of items inside another list. That's why I forced to use the Expander component to display the data on the UI.

    At the same time, I need to load more items when the Expander bottom reaches. But Expander doesn't provide the related event because it is not a scrollable control. So that I tried to find out an event for the ScrollView component. But no luck for that also.

    Finally, I decided to change the data to a single list from a list inside another list. I have converted that using some for loops and now the data is suitable for ListView. And I have implemented the load more feature using the ItemAppearing event.

    Thanks