How to show a pop-up message when clicking the image in the .NET MAUI Rotator?
This section explains how to display a pop-up message when an image is clicked in the .NET MAUI Rotator. You can achieve it by following these steps:
Step 1: Initialize the Rotator control on the XAML page with the required assemblies.
XAML:
<syncfusion:SfRotator x:Name="rotator" />
Step 2: Create a Model and ViewModel classes.
Step 3: 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 4: Bind the collection to the Image property in the ItemTemplate. Use TapGestureRecognizer
for event handling.
XAML:
<syncfusion:SfRotator
VerticalOptions="Center"
x:Name="rotator"
ItemsSource="{Binding ImageCollection}">
<syncfusion:SfRotator.ItemTemplate>
<DataTemplate>
<Grid>
<Image Source="{Binding Image}"/>
<Grid.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped" />
</Grid.GestureRecognizers>
</Grid>
</DataTemplate>
</syncfusion:SfRotator.ItemTemplate>
</syncfusion:SfRotator>
Step 5: Implement the event method to show a pop-up message.
C#:
private void TapGestureRecognizer_Tapped(object sender, TappedEventArgs e)
{
DisplayAlert("Image", "Rotator Item has been tapped", "Ok");
}
Output:
Download the complete sample from GitHub.
Conclusion:
I hope you enjoyed learning how to show a pop-up message when clicking an image in the .NET MAUI 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!