Articles in this section
Category / Section

How to create a collection of .NET MAUI CheckBox (SfCheckBox)?

2 mins read

This article describes how to create the collection of .NET MAUI CheckBox. Let’s take an example to display the number of .NET MAUI CheckBox for addressing the Cities. Here, I use ItemsSource to show the collection of items. In ItemTemplate, the CityName property hold the Text value of RadioButton. BindingContext is used to bind the ViewModel class.
The following code explains how to create a collection of .NET MAUI CheckBox,
XAML:

<ContentPage.BindingContext>
    <local:ViewModel/>
</ContentPage.BindingContext>
<StackLayout BindableLayout.ItemsSource="{Binding Cities}">
        <BindableLayout.ItemTemplate>
            <DataTemplate>
                <buttons:SfCheckBox Text="{Binding CityName}" />
            </DataTemplate>
        </BindableLayout.ItemTemplate>
</StackLayout>

C#:

public class City
{
    public string CityName { get; set; }
}

public class ViewModel
{
    private ObservableCollection<city> cities;

    public ObservableCollection<city> Cities
    {
        get { return cities; }
        set { cities = value; }
    }
    public ViewModel()
    {
        Cities = new ObservableCollection<city>();
        Cities.Add(new City() { CityName = "Tokyo" });
        Cities.Add(new City() { CityName = "Paris" });
        Cities.Add(new City() { CityName = "New York City" });
        Cities.Add(new City() { CityName = "Singapore" });
        Cities.Add(new City() { CityName = "Vienna" });
        Cities.Add(new City() { CityName = "Sydney" });
        Cities.Add(new City() { CityName = "Zurich" });
        Cities.Add(new City() { CityName = "Toronto" });
        Cities.Add(new City() { CityName = "Copenhagen" });
    }
}
   

Output:

ezgif.com-video-to-gif (13).gif

Conclusion

I hope you enjoyed learning how to create a collection of .NET MAUI CheckBox.

Refer to our .NET MAUI CheckBox’s feature tour page for other groundbreaking feature representations. You can explore our .NET MAUI CheckBox documentation to understand how to present and manipulate data.

For current customers, check out our .NET MAUI components from the License and Downloads page. If you are new to Syncfusion, try our 30-day free trial to check out our .NET MAUI CheckBox and other .NET MAUI components.

Please let us know in the following comments section if you have any queries or require clarifications. 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