How does Xamarin.Forms SfRotator obtain the SelectedIndex?
Steps to get the SelectedIndex in SfRotator:
Using the selectedindex property we can get the current Xamarin Rotator item.
Step 1: Add rotator control in xaml page.
Step 2: Add items to rotator using SfRotatorItem.
Step 3: In the selection changed event using selected index property we can get the selectedindex of the current SfRotator item.
The following code demonstrates how to get the selectedindex in SfRotator.
Xaml Code:
<StackLayout> <syncfusion:SfRotator x:Name="rotator" SelectedIndexChanged="Handle_SelectedIndexChanged" /> </StackLayout>
C# Code:
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
List<SfRotatorItem> collectionOfItems = new List<SfRotatorItem>();
collectionOfItems.Add(new SfRotatorItem() { Image = "movie1.png" });
collectionOfItems.Add(new SfRotatorItem() { Image = "movie2.png" });
collectionOfItems.Add(new SfRotatorItem() { Image = "movie3.png" });
collectionOfItems.Add(new SfRotatorItem() { Image = "movie4.png" });
collectionOfItems.Add(new SfRotatorItem() { Image = "movie5.png" });
rotator.DataSource = collectionOfItems;
}
void Handle_SelectedIndexChanged(object sender, Syncfusion.SfRotator.XForms.SelectedIndexChangedEventArgs e)
{
DisplayAlert("Message", "Rotator SelectedIndex is: " + rotator.SelectedIndex, "Ok");
}
}
Please download the sample from the below link:
Conclusion
I hope you enjoyed learning about how to get the selected index in Xamarin.Forms Rotator?.
You can refer to our Xamarin.Forms Rotator Feature tour page to know about its other groundbreaking feature representations. You can also explore our Xamarin.Forms controls examples to understand how to present and manipulate data.
For current customers, you can check out our Xamarin.Forms controls from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our Xamarin controls.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!