Articles in this section
Category / Section

How to achieve Item Tapped in .NET MAUI Rotator (SfRotator)?

3 mins read

This section explains how to achieve item-tapped functionality in the .NET MAUI Rotator control. Follow these steps:
Here, the ItemTapped property provides the tapped event.

Step 1: Create a Model and ViewModel classes.

Step 2: Define a collection of images in the ViewModel class.

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; }
    }
}

Step 3: Initialize the .NET MAUI Rotator in the XAML page and set the ViewModel class as the BindingContext. Use the ItemTapped property to make items clickable.

XAML:

<syncfusion:SfRotator VerticalOptions="Center" Background="Transparent"
                    x:Name="rotator"  
                    ItemsSource="{Binding ImageCollection}" 
                    ItemTapped="rotator_ItemTapped">

    <syncfusion:SfRotator.ItemTemplate>
        <DataTemplate>
            <Image Source="{Binding Image}"/>
        </DataTemplate>
    </syncfusion:SfRotator.ItemTemplate>
</syncfusion:SfRotator>

Step 4: Implement the event method triggered by the ItemTapped property to handle item taps.

C#:

        private void rotator_ItemTapped(object sender, EventArgs e)
        {
            DisplayAlert("Image", "Rotator Item has been tapped", "Ok");
        }

Output:

qemu-system-x86_64_uY18QNcUUg-ezgif.com-video-to-gif-converter.gif

Download the complete sample from GitHub

Conclusion:
I hope you enjoyed learning how to achieve the item tap functionality in the .NET MAUI Rotator.

You can refer to our .NET MAUI Rotator feature tour page to learn about its other groundbreaking feature representations. 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!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied