Category / Section
How to scale the Carousel items
1 min read
We can scale the CarouselItems by using ScaleOffset property in Carousel. ScaleOffset is used to scale the unselected items that are arranged to the both sides of the selected item. The default value is 0.7f.
The below code illustrates how to use the ScaleOffset value for carousel items.
C#
public partial class KBSolutionPage : ContentPage { public KBSolutionPage() { InitializeComponent(); //Create an instance of carousel SfCarousel sfCarousel = new SfCarousel(); //ScaleOffset property is used to scale the unselected items in carousel control. sfCarousel.ScaleOffset = 1; if (Device.OS == TargetPlatform.Android) { sfCarousel.ItemWidth = 170; sfCarousel.ItemHeight = 250; } if (Device.OS == TargetPlatform.iOS) { sfCarousel.ItemWidth = 150; sfCarousel.ItemHeight = 300; } 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; }); //Assign the collection of customview's collection to carousel's collection property 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; } } }