2X faster development
The ultimate Xamarin UI toolkit to boost your development speed.
Carousel control allows you to navigate through the image data in an interactive way so that they can be viewed or selected. Also, it provides various customization options for its item arrangements. You can get the view of Carousel from any one of the following ways:
The following section illustrates how to create the carousel control in Xamarin.Forms Android platforms.
Needed assemblies: For getting the view of carousel control, you should add the following assemblies in both PCL and Android in Xamarin.
Note: It is more important to add Xamarin.Android.Support.v17.Leanback library to get the carousel‘s Linear mode in Android platform.
C#public partial class KBSolutionPage : ContentPage { public KBSolutionPage() { InitializeComponent(); SfCarousel sfCarousel = new SfCarousel(); sfCarousel.ItemWidth = 170; sfCarousel.ItemHeight = 250; ObservableCollection<SfCarouselItem> collectionOfItems = new ObservableCollection<SfCarouselItem>(); collectionOfItems.Add(new SfCarouselItem() { ImageName = "images1.png" }); collectionOfItems.Add(new SfCarouselItem() { ImageName = "images2.png" }); collectionOfItems.Add(new SfCarouselItem() { ImageName = "images3.png" }); collectionOfItems.Add(new SfCarouselItem() { ImageName = "images4.png" }); collectionOfItems.Add(new SfCarouselItem() { ImageName = "images5.png" }); collectionOfItems.Add(new SfCarouselItem() { ImageName = "images6.png" }); sfCarousel.DataSource = collectionOfItems; this.Content = sfCarousel; } }
C#:public partial class KBSolutionPage : ContentPage { public KBSolutionPage() { InitializeComponent(); //Initialize the carousel control SfCarousel sfCarousel = new SfCarousel(); sfCarousel.ItemWidth = 170; sfCarousel.ItemHeight = 250; var carouselModel = new List<CarouselModel> { new CarouselModel ("image1.png"), new CarouselModel ("image2.png"), new CarouselModel ("image3.png"), new CarouselModel ("image4.png"), new CarouselModel ("image5.png") }; var carouselModelDataTem= new DataTemplate(() => { var grid = new Grid(); var nameLabel = new Image(); nameLabel.SetBinding(Image.SourceProperty, "Image"); grid.Children.Add(nameLabel); return grid; }); sfCarousel.ItemTemplate = carouselModelDataTem ; sfCarousel.DataSource = carouselModel; this.Content = sfCarousel; } } public class CarouselModel { public CarouselModel(string imagestr) { Image = imagestr; } private string _image; public string Image { get { return _image; } set { _image = value; } } }
Output:
Sample Link: |
2X faster development
The ultimate Xamarin UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.
I am using CarouselItem to populate the images and it's not working for me. I have followed all the steps above. Thanks!
Hi Mohanmed Yousuf,
Thanks for your update.
We have checked the published knowledge base's carousel code (both ways). We were unable to reproduce the reported issue. Here, we have republished this KB with sample. The attached sample illustrates the both ways to render the carousel control. Please download the sample from this page.
Please look at the sample and if you are facing the same issue, update us with mode details (device specification, Syncfusion Assemblies version) to analyze further and provide an appropriate solution.
And for getting immediate reply regarding your queries please contact support@syncfusion.com
Regards,