Category / Section
How to add the scrollbar to the Carousel items?
1 min read
User can add the ScrollBar to the Carousel Items. It can be achieved by adding the ScrollViewer control inside the ItemTemplate of Carousel control. The following code demonstrates the same.
XAML
<Window.DataContext> <local:ViewModel/> </Window.DataContext> <!-- Carousel control --> <syncfusion:Carousel Height="300" x:Name="carousel" ItemsSource="{Binding Collection}"> <!-- Set Height For Carousel Items --> <syncfusion:Carousel.ItemContainerStyle> <Style TargetType="syncfusion:CarouselItem"> <Setter Property="Height" Value="140" /> </Style> </syncfusion:Carousel.ItemContainerStyle> <!-- For Adding ScrollBar to Carousel Items --> <syncfusion:Carousel.ItemTemplate> <DataTemplate> <Grid > <!-- Add ScrollBar --> <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" > <Border x:Name="border" > <Grid Width="150" Height="300"> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <TextBox TextWrapping="Wrap" Grid.Row="0" Background="Green" Foreground="White" Text="The Carousel is a circular conveyor used on which objects are displayed and rotated. The Carousel control provides a 3D interface for displaying objects with interactive navigation, Data Binding Path, Items Per Page, Scaling and Skewing."/> <Image Source="/Images1/dodsworth.png" Grid.Row="1" /> </Grid> </Border> </ScrollViewer> </Grid> </DataTemplate> </syncfusion:Carousel.ItemTemplate>
C#
public class Model { } public ObservableCollection<Model> Collection { get; set; } public ViewModel() { Collection = new ObservableCollection<Model>(); Collection.Add(new Model() ); Collection.Add(new Model() ); Collection.Add(new Model() ); Collection.Add(new Model() ); Collection.Add(new Model() ); }
Screenshot
Sample: CarouselSample