How to detect scroll completed or end after scrolling in CarouselView in Xamarin Forms?

Viewed 310

I have a CarouselView and I want to have some animation after Items are scrolled manually (by swiping left or right on CarouselView). I want to know when the scroll animation is complete or ended. Is there any way, I did not find anything related to this in the Official Docs.

Here is my code

<CarouselView x:Name="carouselView" Scrolled="CarouselViewScrolled" Loop="False" HorizontalOptions="FillAndExpand" >
    <CarouselView.ItemsSource>
        <x:Array Type="{x:Type ContentView}">
            <ContentView>
                <!--Defining View 1-->
            </ContentView>
            <ContentView>
                <!--Defining View 2-->
            </ContentView>
            <ContentView>
                <!--Defining View 3-->
            </ContentView>
    </CarouselView.ItemsSource>
</CarouselView>
1 Answers

As far as I know, use CurrentItemChanged instead of Scrolled property of CarouselView.

Change your XAML as

<CarouselView x:Name="carouselView" CurrentItemChanged="CarouselViewItemChanged">
...

If you want to get current Item after Swiping to a new Item use carouselView.Position.

In your C# Code behind

void CarouselViewItemChanged(object sender, CurrentItemChangedEventArgs e)
{
    Debug.WriteLine("Position: " + carouselView.Position);
}

Refer this for Official Documentation

Related