Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the page programatically in CarouselPage in Xamarin.forms? [closed]

I'm using CarouselPage class to implement Horizontal Slider in Xamarin.Forms. I am going to make CarouselPage class to move to the next page from tapping on the page, not swiping.

Is it possible? Can anyone help me?

Thanks in advance.

like image 481
Phoenix Avatar asked Dec 05 '22 21:12

Phoenix


1 Answers

You could add a TapGestureRecognizer to your Page and wire it up to change the CurrentPage of the CarouselPage. Below is an extension method I wrote to move the current page index of a CarouselPage to the right. Calling this method from a TapGestureRecognizer connected to a child page should give you the desired functionality.

public static void PageRight(this CarouselPage carouselPage)
{
    var pageCount = carouselPage.Children.Count;
    if (pageCount < 2) 
        return;

    var index = carouselPage.Children.IndexOf(carouselPage.CurrentPage);
    index++;
    if (index >= pageCount) 
        index = 0;

    carouselPage.CurrentPage = carouselPage.Children[index];
}
like image 83
Will Decker Avatar answered Dec 08 '22 09:12

Will Decker