)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to render a Carousel like Xamarin Carousel Page

Platform: Xamarin.Forms |
Control: SfCarousel |
Published Date: March 1, 2017 |
Last Revised Date: June 24, 2019

Xamarin CarouselPage provides a support to swipe the pages. We can achieve the same by using Syncfusion SfCarousel control with Linear mode. The default mode of carousel is “Default”. The below code illustrates the way to achieve this.

 

C#

public partial class CarouselFeatureSamplePage : ContentPage
{
public CarouselFeatureSamplePage()
{
 
    //Initialize the carousel control
 
    SfCarousel sfCarousel = new SfCarousel();
 
 
    if (Device.OS == TargetPlatform.Android)
    {
        sfCarousel.ItemWidth = 360;
        sfCarousel.ItemHeight = 550;
    }
    if (Device.OS == TargetPlatform.iOS)
    {
        sfCarousel.ItemWidth = 360;
        sfCarousel.ItemHeight = 530;
    }
    // To obtain the carouselPage view need to use Linear mode of carousel
    sfCarousel.ViewMode = ViewMode.Linear;
 
    ObservableCollection<SfCarouselItem> collectionOfItems = new ObservableCollection<SfCarouselItem>();
 
    StackLayout firstItem = new StackLayout() { BackgroundColor = Color.Green };
    firstItem.Children.Add(new Label() { Text = "CarouselPage 1", FontSize = 20, TextColor = Color.White, HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand });
 
    StackLayout secondItem = new StackLayout() { BackgroundColor = Color.Red };
    secondItem.Children.Add(new Label() { Text = "CarouselPage 2", FontSize = 20, TextColor = Color.White, HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand });
 
    StackLayout thirdItem = new StackLayout() { BackgroundColor = Color.Blue };
    thirdItem.Children.Add(new Label() { Text = "CarouselPage 3", FontSize = 20, TextColor = Color.White, HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand });
 
    collectionOfItems.Add(new SfCarouselItem() { ItemContent = firstItem, HeightRequest = 900, WidthRequest = 900 });
    collectionOfItems.Add(new SfCarouselItem() { ItemContent = secondItem });
    collectionOfItems.Add(new SfCarouselItem() { ItemContent = thirdItem });
 
    sfCarousel.DataSource = collectionOfItems;
 
    this.Content = sfCarousel;
}
 
 
}
 

 

 

Carousel.png

 

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon