Articles in this section
Category / Section

How to create Carousel sample in Xamarin.Forms Carousel platform?

3 mins read

Xamarin Carousel control allows navigating through image data in an interactive way so that they can be viewed or selected. Also, provides various customization options for its item arrangements. We can get the view of Carousel in Xamarin.Forms UWP platform from any one of the following ways,

  1. Using CarouselItem
  2. Using ItemTemplate

 

The below illustrates how to create the carousel control in Xamarin.Forms UWP platforms.

 

Needed assemblies:

For getting the view of carousel control, need to add the following assemblies in both PCL and UWP in Xamarin.

 

Project

Assemblies required

PCL

pcl\Syncfusion.SfCarousel.XForms.dll

UWP

uwp\Syncfusion.SfCarousel.UWP.dll
uwp\Syncfusion.SfCarousel.XForms.dll
uwp\Syncfusion.SfCarousel.XForms.UWP.dll

 

 

  1. Create a carousel control using CarouselItem

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;
}
}

 

  1. Create a carousel control using ItemTemplate

C#

public partial class KBSolutionPage : ContentPage
{
public KBSolutionPage()
{
    InitializeComponent();
    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 carouselModelDataTemplate = new DataTemplate(() =>
    {
        var grid = new Grid();
        var nameLabel = new Image();
        nameLabel.SetBinding(Image.SourceProperty, "Image");
        grid.Children.Add(nameLabel);
        return grid;
    });
    sfCarousel.ItemTemplate = carouselModelDataTemplate;
    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; }
}
}
 

 

Carousel

 

 

 

 

Conclusion

I hope you enjoyed learning about how to create Carousel sample in Xamarin.Forms platform.

You can refer to our Xamarin.Forms Carousel feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!


Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied