How to create a collection of .NET MAUI Radio Button (SfRadioButton)?
This article describes how to create a collection of .NET MAUI RadioButton. In this example, I will showcase multiple .NET MAUI RadioButtons representing various cities. The ItemsSource
property is used to bind the collection of items, and the ItemTemplate
specifies that the CityName
property holds the text value for each RadioButton.
XAML:
<StackLayout>
<buttons:SfRadioGroup x:Name="radioGroup"
BindableLayout.ItemsSource="{Binding Cities}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<buttons:SfRadioButton
Text="{Binding CityName}" />
</DataTemplate>
</BindableLayout.ItemTemplate>
</buttons:SfRadioGroup>
</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" });
Cities.Add(new City() { CityName = "Melbourne" });
Cities.Add(new City() { CityName = "Dubai" });
}
}
Output:
Conclusion:
I hope you enjoyed learning how to create a collection of .NET MAUI Radio Button (SfRadioButton).
Refer to our .NET MAUI RadioButton’s feature tour page for other groundbreaking feature representations. You can explore our .NET MAUI RadioButton 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 RadioButton 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!