How can I change the page programmatically in the Carousel in Xamarin.forms?
1 answer
You can add TapGestureRecognizer to your page and connect it to change CurrentPage in CarouselPage. Below is an extension method I wrote to move the current index of the CarouselPage to the right. Calling this method from a TapGestureRecognizer attached to the child page should provide you with the functionality you want.
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];
}
+10
source to share