Skip to main content
Version: 11.0.x

Carousel

The carousel has an items collection, and displays each item as a page, in sequence, so that it fills the control.

You can use the carousel control to create a slide show.

Useful Properties

You will probably use these properties most often:

PropertyDescription
ItemsSourceThe bound collection that is used as the data source for the control.
ItemsControl.ItemTemplateThe item template, contains a DataTemplate which will be applied to individual items and can be used to change how items look.
ItemsControl.ItemPanelThe container panel to place items in. See this page to customise the ItemsPanel.
ItemsControl.StylesThe style that is applied to any child element of the ItemControl.

Example

This example has three images in the items collection, with buttons to move the display forwards and back. The buttons have click event handlers in the C# code-behind.

<Panel>
<Carousel Name="slides" >
<Carousel.PageTransition >
<CompositePageTransition>
<PageSlide Duration="0:00:01.500" Orientation="Horizontal" />
</CompositePageTransition>
</Carousel.PageTransition>
<Carousel.Items>
<Image Source="avares://AvaloniaControls/Assets/pipes.jpg" />
<Image Source="avares://AvaloniaControls/Assets/controls.jpg" />
<Image Source="avares://AvaloniaControls/Assets/vault.jpg" />
</Carousel.Items>
</Carousel>
<Panel Margin="20">
<Button Background="White" Click="Previous">&lt;</Button>
<Button Background="White" Click="Next"
HorizontalAlignment="Right">&gt;</Button>
</Panel>
</Panel>
C#
using Avalonia.Controls;
using Avalonia.Interactivity;

namespace AvaloniaControls.Views
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

public void Next(object source, RoutedEventArgs args)
{
slides.Next();
}

public void Previous(object source, RoutedEventArgs args)
{
slides.Previous();
}
}
}

More Information

For the complete API documentation about this control, see here.

View the source code on GitHub Carousel.cs