Articles in this section
Category / Section

How to create .NET MAUI RadioGroup in RadioButton(SfRadioButton)?

3 mins read

This article shows how to create the .NET MAUI RadioGroup in the .NET MAUI RadioButton to obtain a single selection among the multiple choices.

The following is a step-by-step guide on how to create a Radio Button group in .NET MAUI RadioButton:

Step 1: Initialize the Radio button
Firstly, add a layout, initialize the radio button group and the button for using the Command property from the .NET MAUI, then set the text for each radio button according to your specifications. You may also bind using the binding context. The following code shows you how to set the Radio button group.
XAML:

<StackLayout Spacing="30" >
        <buttons:SfRadioGroup>
            <buttons:SfRadioButton HorizontalTextAlignment="Start" 
                                   Text="Credit card" FontSize="20"  />
            <buttons:SfRadioButton HorizontalTextAlignment="Start" 
                                   Text="Debit Card"  FontSize="20" />
            <buttons:SfRadioButton HorizontalTextAlignment="Start" 
                                   Text="Net banking"  FontSize="20" />
            <buttons:SfRadioButton HorizontalTextAlignment="Start" 
                                   Text="Cash On Delivery"  FontSize="20" />
        </buttons:SfRadioGroup>
        <Button WidthRequest="200" 
                Text="Proceed Transaction" 
                Command="{Binding TransactionCommmand}"/>
    </StackLayout>
           

Step 2: Initialize button command in cs file
Include the C Sharp code in the file behind, then use the constructor to initialize the command on each button click.
C#:

public class ViewModel
{
    private bool isChecked = true;

    public Command TransactionCommmand { get; set; }
    public bool IsChecked
    {
        get { return isChecked; }
        set { isChecked = value; }
    }

    public ViewModel()
    {
        TransactionCommmand = new Command(DoTransaction);
    }

    private void DoTransaction()
    {
        App.Current.MainPage.DisplayAlert("Hello", "Transaction is Initiated ", "Ok");
    }
    
}

Output:

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

Conclusion:
I hope you enjoyed learning how to create a Radio Button group 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!

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