Articles in this section
Category / Section

How to add Images in the .NET MAUI Segmented Control (SfSegmentedControl)?

2 mins read

In the Syncfusion® .NET MAUI Segmented Control, you can add images to the segmented control as demonstrated below:

XAML:

Initialize the SfSegmentedControl with an ItemsSource for images using the following code sample:

<buttons:SfSegmentedControl x:Name="segmentsImageInfo"
                           SelectedIndex="3"
                           ItemsSource="{Binding ImagesCollection}">
</buttons:SfSegmentedControl>

C#:

Create a view model to add images, where an observable collection is populated with image objects.

public class AddImageViewModel
{
   public AddImageViewModel()
   {
       this.InitializeImageCollection();
   }
   public List<SfSegmentItem> ImagesCollection { get; set; }

   private void InitializeImageCollection()
   {
       this.ImagesCollection = new List<SfSegmentItem>
       {
           new SfSegmentItem() { ImageSource = "boy1.png" },
           new SfSegmentItem() { ImageSource = "girl1.png" },
           new SfSegmentItem() { ImageSource = "girl2.png" },
           new SfSegmentItem() { ImageSource = "boy2.png" },
           new SfSegmentItem() { ImageSource = "girl3.png" },
       };
   }
}

XAML:

Set up a ContentPage with the BindingContext to an instance of the AddImageViewModel class and display images based on the ImageCollection of the AddImageViewModel class.

<ContentPage.BindingContext>
   <local:AddImageViewModel/>
</ContentPage.BindingContext>

<buttons:SfSegmentedControl x:Name="segmentsImageInfo"
                           SelectedIndex="3"
                           ItemsSource="{Binding ImagesCollection}">
</buttons:SfSegmentedControl>

Download the complete sample from GitHub.

Output:

AddImage.png

Conclusion:

I hope you enjoyed learning how to add images in the .NET MAUI Segmented Control (SfSegmentedControl).

Refer to our .NET MAUI Segmented Control feature tour page to learn about its other groundbreaking feature representations. You can explore our .NET MAUI Segmented Control documentation to understand how to present and manipulate data.

Check out our .NET MAUI components from the License and Downloads page for current customers. If you are new to Syncfusion®, try our 30-day free trial to check out our .NET MAUI Segmented Control 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. 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