Hi,
I'm using SfRadioButton and SfRadioButtonGroup.
How can I create a group and binding value of an button in group to an enum?
For example, I have a group radio button contains 7 radio buttons describe 7 days of weeks. How can I bind the value of the checked radio button to a variable instead of using 7 variables?
Thanks and best regards,
TH
Hi Thanh Hai Dang,
Greetings from Syncfusion support!
Query: How can I bind the value of the checked radio button to a variable instead of using 7 variables?
In response to your query, we recommend using the SelectedValue property from the SfRadioGroup, as shown in the code snippet below. This approach will help you avoid binding multiple variables to individual RadioButton components.
Code snippet:
|
<StackLayout> <HorizontalStackLayout Spacing="5" HorizontalOptions="Center"> <Label Text="Selected Item: " FontAttributes="Bold"/> <Label Text="{Binding SelectedItem}" /> </HorizontalStackLayout> <buttons:SfRadioGroup x:Name="radioButton" SelectedValue="{Binding SelectedItem}" CheckedChanged="OnCheckedChanged"> <buttons:SfRadioButton Text="Sunday" Value="Sunday"/> … <buttons:SfRadioButton Text="Saturday" Value="Saturday"/> </buttons:SfRadioGroup> </StackLayout> |
By using this method, you can easily retrieve the selected value from the radio button group and bind it to a single variable.
For more detail, please refer to below help documentation:
Grouping in .NET MAUI Radio Button Control | Syncfusion
For your convenience, we have attached a sample project demonstrating this approach. We encourage you to review the sample and integrate this method into your application.
If you have any further questions, concerns, or need additional assistance, please don’t hesitate to reach out. We’re here to help!
Regards,
Brundha V
Hi Brundha V,
Thank you for your effort. I'm using Syncfusion version 26.2.4 and seem the SelectedValue property in SfRadioGroup and Value property in SfRadioButton haven't defined yet.
What the minimum version can I use with the properties?
Thanks and best regards,
TH
Hi Thanh Hai Dang,
Thank you for the update.
Query: What the minimum version can I use with the properties?
In response to your query, version 27.1.48 of the Syncfusion Maui Buttons NuGet package is the minimum version where the SelectedValue property is available for the RadioGroup. Please use this version, and let us know if you have any concerns.
For more details, you can refer to the release notes:
Essential Studio for MAUI 2024 Volume 3 Main Release Release Notes (syncfusion.com)
Let us know if you need any further assistance!
Regards,
Brundha V