How to Obtain the Selected Index in .NET MAUI Rotator (SfRotator)?
This document describes how to obtain the selected index in the .NET MAUI Rotator. We can achieve it by following the steps below,
Here, the SelectedIndex property is used to get the index of the selected item.
Step 1: Initialize the Rotator control in the XAML page with all required assemblies.
Step 2: Add items to the Rotator using SfRotatorItem.
Step 3: Implement the SelectedIndexChanged event in the Rotator control.
Step 4: Use the SelectedIndex property in the selection changed event to get the index of the selected item.
The following code demonstrates how to get the selectedindex in SfRotator.
XAML
<syncfusion:SfRotator x:Name="rotator" SelectedIndexChanged="rotator_SelectedIndexChanged" />
C#
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
List<SfRotatorItem> collectionOfItems = new List<SfRotatorItem>();
collectionOfItems.Add(new SfRotatorItem() { Image = "image1.png" });
collectionOfItems.Add(new SfRotatorItem() { Image = "image2.png" });
collectionOfItems.Add(new SfRotatorItem() { Image = "image3.png" });
collectionOfItems.Add(new SfRotatorItem() { Image = "image4.png" });
collectionOfItems.Add(new SfRotatorItem() { Image = "image5.png" });
rotator.ItemsSource = collectionOfItems;
}
}
private void rotator_SelectedIndexChanged(object sender, Syncfusion.Maui.Core.Rotator.SelectedIndexChangedEventArgs e)
{
DisplayAlert("Message", "Selected Index : " + rotator.SelectedIndex, "Ok");
}
Output:
Conclusion:
I hope you enjoyed learning how to obtain the selected index in the .NET MAUI Rotator.
You can 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!