Class SfCarousel
The SfCarousel class represents a control that allows user navigate through a collection of galleried items.
Inheritance
Namespace: Syncfusion.Maui.Toolkit.Carousel
Assembly: Syncfusion.Maui.Toolkit.dll
Syntax
public class SfCarousel : View, ICarousel, IView, IElement, ITransform
Examples
The below example shows how to initialize the SfCarousel with model and view model.
public class ImageModel
{
public string Image { get; set; }
public ImageModel(string image)
{
Image = image;
}
}
public class GalleryViewModel
{
private ObservableCollection<ImageModel> imageCollection;
public ObservableCollection<ImageModel> ImageCollection { get; set; }
public GalleryViewModel()
{
ImageCollection = new ObservableCollection<ImageModel>()
{
new ImageModel("image1.png"),
new ImageModel("image2.png"),
new ImageModel("image3.png"),
};
}
}
<ContentPage.BindingContext>
<local:GalleryViewModel x:Name="galleryViewModel" />
</ContentPage.BindingContext>
<ContentPage.Resources>
<ResourceDictionary>
<DataTemplate x:Key="itemTemplate">
<Grid>
<Image x:Name="image" Source="{Binding Image}" />
</Grid>
</DataTemplate>
</ResourceDictionary>
</ContentPage.Resources>
<ContentPage.Content>
<carousel:SfCarousel
x:Name="carousel"
ItemTemplate="{x:StaticResource itemTemplate}"
ItemsSource="{Binding ImageCollection}" />
</ContentPage.Content>
Constructors
SfCarousel()
Initializes a new instance of the SfCarousel class.
Declaration
public SfCarousel()
Fields
AllowLoadMoreProperty
Identifies the AllowLoadMore bindable property.
Declaration
public static readonly BindableProperty AllowLoadMoreProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for AllowLoadMore bindable property. |
DurationProperty
Identifies the Duration bindable property.
Declaration
public static readonly BindableProperty DurationProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for Duration bindable property. |
EnableInteractionProperty
Identifies the EnableInteraction bindable property.
Declaration
public static readonly BindableProperty EnableInteractionProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for EnableInteraction bindable property. |
EnableVirtualizationProperty
Identifies the EnableVirtualization bindable property.
Declaration
public static readonly BindableProperty EnableVirtualizationProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for EnableVirtualization bindable property. |
ItemHeightProperty
Identifies the ItemHeight bindable property.
Declaration
public static readonly BindableProperty ItemHeightProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for ItemHeight bindable property. |
ItemSpacingProperty
Identifies the ItemSpacing bindable property.
Declaration
public static readonly BindableProperty ItemSpacingProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for ItemSpacing bindable property. |
ItemsSourceProperty
Identifies the ItemsSource bindable property.
Declaration
public static readonly BindableProperty ItemsSourceProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for ItemsSource bindable property. |
ItemTemplateProperty
Identifies the ItemTemplate bindable property.
Declaration
public static readonly BindableProperty ItemTemplateProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for ItemTemplate bindable property. |
ItemWidthProperty
Identifies the ItemWidth bindable property.
Declaration
public static readonly BindableProperty ItemWidthProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for ItemWidth bindable property. |
LoadMoreItemsCountProperty
Identifies the LoadMoreItemsCount bindable property.
Declaration
public static readonly BindableProperty LoadMoreItemsCountProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for LoadMoreItemsCount bindable property. |
LoadMoreViewProperty
Identifies the LoadMoreView bindable property.
Declaration
public static readonly BindableProperty LoadMoreViewProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for LoadMoreView bindable property. |
OffsetProperty
Identifies the Offset bindable property.
Declaration
public static readonly BindableProperty OffsetProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for Offset bindable property. |
RotationAngleProperty
Identifies the RotationAngle bindable property.
Declaration
public static readonly BindableProperty RotationAngleProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for RotationAngle bindable property. |
ScaleOffsetProperty
Identifies the ScaleOffset bindable property.
Declaration
public static readonly BindableProperty ScaleOffsetProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for ScaleOffset bindable property. |
SelectedIndexProperty
Identifies the SelectedIndex bindable property.
Declaration
public static readonly BindableProperty SelectedIndexProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for SelectedIndex bindable property. |
SelectedItemOffsetProperty
Identifies the SelectedItemOffset bindable property.
Declaration
public static readonly BindableProperty SelectedItemOffsetProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for SelectedItemOffset bindable property. |
SwipeMovementModeProperty
Identifies the SwipeMovementMode bindable property.
Declaration
public static readonly BindableProperty SwipeMovementModeProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for SwipeMovementMode bindable property. |
ViewModeProperty
Identifies the ViewMode bindable property.
Declaration
public static readonly BindableProperty ViewModeProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for ViewMode bindable property. |
Properties
AllowLoadMore
Gets or sets a value indicating whether the carousel control is configured to load additional items dynamically.
Declaration
public bool AllowLoadMore { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Examples
Below is an example of how to configure the AllowLoadMore property using XAML and C#:
Duration
Gets or sets the duration for the selection animation in the carousel, allowing you to adjust the delay of the effect.
Declaration
public int Duration { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 | The default value is 600 milliseconds. |
Examples
Below is an example of how to configure the Duration property using XAML and C#:
EnableInteraction
Gets or sets a value indicating whether user interaction with the carousel is enabled or disabled.
Declaration
public bool EnableInteraction { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Examples
Below is an example of how to configure the EnableInteraction property using XAML and C#:
EnableVirtualization
Gets or sets a value indicating whether the virtualization is enabled or not.
Declaration
public bool EnableVirtualization { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Remarks
This property is effective only when the carousel's view mode is set to Linear.
Examples
Below is an example of how to set the EnableVirtualization property using XAML and C#:
ItemHeight
Gets or sets the height of each item in the carousel, allowing customization to suit design specifications.
Declaration
public int ItemHeight { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 | The default value is 350 for desktop platforms and 300 for mobile devices. |
Examples
Below is an example of how to configure the ItemHeight property using XAML and C#:
ItemSpacing
Gets or sets the spacing value between items in the carousel. This property adjusts the space separating each item.
Declaration
public int ItemSpacing { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 | The default value is 12. |
Remarks
This property is effective only when the view mode is set to linear.
Examples
Below is an example of how to configure the ItemSpacing property using XAML and C#:
ItemsSource
Gets or sets the collection of items to be displayed in the carousel, allowing each item to have a different view based on the template.
Declaration
public IEnumerable<object> ItemsSource { get; set; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Object> | The default value is null, indicating no items are initially set. |
Examples
Below is an example of how to configure the ItemsSource property using XAML and C#:
ItemTemplate
Gets or sets the data template that defines the visual representation of each item in the carousel.
Declaration
public DataTemplate ItemTemplate { get; set; }
Property Value
Type | Description |
---|---|
Microsoft.Maui.Controls.DataTemplate | The default value is null, indicating no template is set initially. |
Examples
Below is an example of how to configure the ItemTemplate property using XAML and C#:
<carousel:SfCarousel
x:Name="carousel">
<carousel:SfCarousel.ItemTemplate>
<DataTemplate>
<Image Aspect = "Fill"
HeightRequest="100"
Source="{Binding ImageName}"
WidthRequest="100" />
</DataTemplate>
</carousel:SfCarousel.ItemTemplate>
</carousel:SfCarousel>
ItemWidth
Gets or sets the width of each item in the carousel, allowing customization to suit design specifications.
Declaration
public int ItemWidth { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 | The default value is 250 for desktop platforms and 200 for mobile devices. |
Examples
Below is an example of how to configure the ItemWidth property using XAML and C#:
LoadMoreItemsCount
Gets or sets the number of additional items to load when the load more functionality is triggered in the carousel.
Declaration
public int LoadMoreItemsCount { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 | The default value is 3. |
Examples
Below is an example of how to configure the LoadMoreItemsCount property using XAML and C#:
LoadMoreView
Gets or sets the custom view displayed when additional items are loaded in the carousel, replacing the default "Load More" label.
Declaration
public View LoadMoreView { get; set; }
Property Value
Type | Description |
---|---|
Microsoft.Maui.Controls.View | The default value is null, indicating no custom view is set initially. |
Examples
Below is an example of how to configure the LoadMoreView property using XAML and C#:
<carousel:SfCarousel
x:Name="carousel"
AllowLoadMore="True"
LoadMoreItemsCount="2">
<carousel:SfCarousel.LoadMoreView>
<Border Stroke="LightGray" StrokeThickness="1" StrokeShape="RoundRectangle 8">
<Label
HorizontalTextAlignment="Center"
Text="Load More View"
VerticalTextAlignment="Center" />
</Border>
</carousel:SfCarousel.LoadMoreView>
</carousel:SfCarousel>
Offset
Gets or sets the spacing between each item in the carousel when the view mode is set to default, allowing for visual separation.
Declaration
public float Offset { get; set; }
Property Value
Type | Description |
---|---|
System.Single | The default value is 40f for desktop and 18f for mobile devices. |
Remarks
This property is effective only in the default view mode.
Examples
Below is an example of how to configure the Offset property using XAML and C#:
RotationAngle
Gets or sets the angle at which unselected items are tilted in the carousel.
Declaration
public int RotationAngle { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 | The default value is 45 degrees. |
Remarks
This property is effective only when the view mode is set to the default mode.
Examples
Below is an example of how to configure the RotationAngle property using XAML and C#:
ScaleOffset
Gets or sets the scaling ratio that differentiates unselected items in the carousel when the view mode is set to default.
Declaration
public float ScaleOffset { get; set; }
Property Value
Type | Description |
---|---|
System.Single | The default value is 0.8f for desktop and 0.7f for mobile devices. |
Remarks
This property is effective only in the default view mode.
Examples
Below is an example of how to configure the ScaleOffset property using XAML and C#:
SelectedIndex
Gets or sets the index of the item that is currently selected and centered in the carousel control.
Declaration
public int SelectedIndex { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 | The default value is 0, indicating the first item. |
Examples
Below is an example of how to set the SelectedIndex property using XAML and C#:
SelectedItemOffset
Gets or sets the space between the selected item and unselected items in the carousel when the view mode is set to default.
Declaration
public int SelectedItemOffset { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 | The default value is 20 for Windows and 40 for other platforms. |
Remarks
This property is effective only in the default view mode.
Examples
Below is an example of how to configure the SelectedItemOffset property using XAML and C#:
SwipeMovementMode
Gets or sets the scroll mode for the carousel, determining whether items are scrolled individually or in groups.
Declaration
public SwipeMovementMode SwipeMovementMode { get; set; }
Property Value
Type |
---|
SwipeMovementMode |
Examples
Below is an example of how to configure the SwipeMovementMode property using XAML and C#:
ViewMode
Gets or sets the mode that determines whether the carousel items are arranged in a default 3D layout or a linear horizontal layout.
Declaration
public ViewMode ViewMode { get; set; }
Property Value
Type | Description |
---|---|
ViewMode | The default value is "Default", indicating the 3D view mode.. |
Examples
Below is an example of how to configure the ViewMode property using XAML and C#:
Methods
LoadMore()
Triggers the loading of additional items into the carousel.
Declaration
public void LoadMore()
MoveNext()
Advances the carousel selection from right to left, incrementing the selected index by one.
Declaration
public void MoveNext()
MovePrevious()
Moves the carousel selection from left to right, decrementing the selected index by one.
Declaration
public void MovePrevious()
Events
SelectionChanged
Triggered when an item is selected from the list of unselected items in the SfCarousel.
Declaration
public event EventHandler<SelectionChangedEventArgs> SelectionChanged
Event Type
Type |
---|
System.EventHandler<SelectionChangedEventArgs> |
SwipeEnded
Triggered when a swipe gesture is completed in the SfCarousel.
Declaration
public event EventHandler<EventArgs> SwipeEnded
Event Type
Type |
---|
System.EventHandler<System.EventArgs> |
SwipeStarted
Triggered when a swipe gesture initiates an item selection in the SfCarousel.
Declaration
public event EventHandler<SwipeStartedEventArgs> SwipeStarted
Event Type
Type |
---|
System.EventHandler<SwipeStartedEventArgs> |