Articles in this section
Category / Section

How to set gap between Unselected items in Xamarin.Forms Carousel?

3 mins read

 

 The space between the Unselected items in SfCarousel control can be customized using the “Offset” property. The default value of the Offset API is 50.

The below code illustrates how to provide the offset value for carousel items.

Code snippet:

public partial class KBSolutionPage  : ContentPage
{
    public KBSolutionPage()
    {
        InitializeComponent();
 
        // Create an instance of carousel control
 
        SfCarousel sfCarousel = new SfCarousel();
 
        // To get the view of carousel , need to assign the ItemHeight and ItemWidth 
 
        if (Device.OS == TargetPlatform.Android)
        {
            sfCarousel.ItemWidth = 170;
            sfCarousel.ItemHeight = 250;
        }
        if (Device.OS == TargetPlatform.iOS)
        {
            sfCarousel.ItemWidth = 150;
            sfCarousel.ItemHeight = 300;
        }
        //Offset property is used to give gap between the unselected items
 
        sfCarousel.Offset = 40;
 
        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")
        };
 
        // Template initialization
 
        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 custom view to carousel's collection
 
        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; }
    }
}

 

Offset – 40:

SfCarousel Offset – 40

 

 

Offset – 100

SfCarousel Offset – 100

 

Conclusion

I hope you enjoyed learning about how to set the gap between Unselected items in Xamarin.Forms Carousel.

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