How to notify the selection changes in .NET MAUI RadioButton (SfRadioButton)?
This article shows how to display a message box showing the text of the selected .NET MAUI RadioButton when changing the selection on a radio button list.
The CheckedChanged event is triggering whenever the selected item changes.
XAML:
<StackLayout>
<buttons:SfRadioGroup x:Name="radioGroup"
CheckedChanged="OnCheckedChanged"
BindableLayout.ItemsSource="{Binding Cities}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<buttons:SfRadioButton
Text="{Binding CityName}" />
</DataTemplate>
</BindableLayout.ItemTemplate>
</buttons:SfRadioGroup>
</StackLayout>
C#:
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private void OnCheckedChanged(object sender, CheckedChangedEventArgs e)
{
App.Current.MainPage.DisplayAlert("Hello", "Selected " + e.CurrentItem.Text, "Ok");
}
}
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 notify the selection changes in .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!