Xamarin.Forms - Sync movements/scrolling of 2 carouselviews

251 views Asked by At

How to "sync" the scrolling/movement of 2 carouselviews?

~ A - B - C - D ... This is the items of carousel 1

~ E - F - G - H ... and this is the items of carousel 2

When I scroll to B from A, I'd like to expect the same goes for carousel 2 in which it moves from E to F.

Any help is appreciated, thanks!

edit: btw, they're on the same page

1

There are 1 answers

4
Jessie Zhang -MSFT On

When I scroll to B from A, I'd like to expect the same goes for carousel 2 in which it moves from E to F.

Yes, you can monitor event PositionChanged of your carouselview, of event PositionChanged is triggered, you can also scroll another carouselview to special position.

Please refer to the following code:

    private void mCarouselView1_PositionChanged(object sender, PositionChangedEventArgs e)
    {
        int previousItemPosition = e.PreviousPosition;
        int currentItemPosition = e.CurrentPosition;

        mCarouselView2.ScrollTo(currentItemPosition);
    }

    private void mCarouselView2_PositionChanged(object sender, PositionChangedEventArgs e)
    {
        int previousItemPosition = e.PreviousPosition;
        int currentItemPosition = e.CurrentPosition;

        mCarouselView1.ScrollTo(currentItemPosition);
    }