How to use the ItemTemplate in the .NET MAUI Rotator?
This section explains how to use the ItemTemplate in the .NET MAUI Rotator. You can achieve it by following these steps:
Step 1: Create Model and ViewModel classes.
Step 2: Define a collection of images in the ViewModel class.
Step 3: Initialize the Rotator control in the XAML page.
Step 4: Bind the collection to the Image property in ItemTemplate using a DataTemplate.
The following code demonstrates how to use the ItemTemplate in SfRotator.
XAML:
<syncfusion:SfRotator x:Name="rotator" ItemsSource="{Binding ImageCollection}">
<syncfusion:SfRotator.ItemTemplate>
<DataTemplate>
<Image Source="{Binding Image}"/>
</DataTemplate>
</syncfusion:SfRotator.ItemTemplate>
</syncfusion:SfRotator>
C#:
public class RotatorModel
{
public RotatorModel(string image)
{
Image = image;
}
private string _image;
public string Image
{
get { return _image; }
set { _image = value; }
}
}
public class RotatorViewModel
{
public RotatorViewModel()
{
ImageCollection.Add(new RotatorModel("image1.png"));
ImageCollection.Add(new RotatorModel("image2.png"));
ImageCollection.Add(new RotatorModel("image3.png"));
ImageCollection.Add(new RotatorModel("image4.png"));
ImageCollection.Add(new RotatorModel("image5.png"));
}
private List<RotatorModel> imageCollection = new List<RotatorModel>();
public List<RotatorModel> ImageCollection
{
get { return imageCollection; }
set { imageCollection = value; }
}
}
Output:
Conclusion:
I hope you enjoyed learning how to use the ItemTemplate in the Rotator.
Refer to our .NET MAUI Rotator feature tour page to learn about its other groundbreaking feature representations. You can explore our .NET MAUI Rotator documentation to understand how to present and manipulate data.
For current customers, check out our .NET MAUI components on the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to explore our .NET MAUI Rotator and other .NET MAUI components.
Please let us know in the comments section if you have any queries or require clarification. You can also contact us through our support forums, Direct-Trac, or feedback portal, or the feedback portal. We are always happy to assist you!