|
1 | | -# Getting-Started-with-.NET-MAUI-RadioButton |
| 1 | +# Getting Started with .NET MAUI RadioButton (SfRadioButton) |
| 2 | + |
| 3 | +This section provides a quick overview for working with the SfRadioButton for .NET MAUI. Walk through the entire process of creating a real world of this control. |
| 4 | + |
| 5 | +## Creating an application using the .NET MAUI Radio Button |
| 6 | + 1. Create a new .NET MAUI application in Visual Studio. |
| 7 | + 2. Syncfusion .NET MAUI components are available on [nuget.org](https://www.nuget.org/). To add SfRadioButton to your project, open the NuGet package manager in Visual Studio, search for Syncfusion.Maui.Buttons and then install it. |
| 8 | + |
| 9 | +## Register the handler |
| 10 | + |
| 11 | +To use this control inside an application, you must register the handler for Syncfusion® core. |
| 12 | + |
| 13 | +```C# |
| 14 | + |
| 15 | +using Microsoft.Extensions.Logging; |
| 16 | +using Syncfusion.Maui.Core.Hosting; |
| 17 | + |
| 18 | +namespace RadioButtonGettingStarted |
| 19 | +{ |
| 20 | + public static class MauiProgram |
| 21 | + { |
| 22 | + public static MauiApp CreateMauiApp() |
| 23 | + { |
| 24 | + var builder = MauiApp.CreateBuilder(); |
| 25 | + builder |
| 26 | + .UseMauiApp<App>() |
| 27 | + .ConfigureSyncfusionCore() |
| 28 | + .ConfigureFonts(fonts => |
| 29 | + { |
| 30 | + fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); |
| 31 | + fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); |
| 32 | + }); |
| 33 | + |
| 34 | +#if DEBUG |
| 35 | + builder.Logging.AddDebug(); |
| 36 | +#endif |
| 37 | + |
| 38 | + return builder.Build(); |
| 39 | + } |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +``` |
| 44 | + |
| 45 | +## Add a basic Radio Button |
| 46 | +1. Import the control namespace `Syncfusion.Maui.Buttons` in XAML or C# code. |
| 47 | +2. Initialize [SfRadioButton](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Buttons.SfRadioButton.html) control. |
| 48 | + |
| 49 | +```xml |
| 50 | +<ContentPage |
| 51 | + . . . |
| 52 | + xmlns:buttons="clr-namespace:Syncfusion.Maui.Buttons;assembly=Syncfusion.Maui.Buttons"> |
| 53 | + <buttons:SfRadioButton x:Name="radioButton"/> |
| 54 | +</ContentPage> |
| 55 | +``` |
| 56 | + |
| 57 | +```C# |
| 58 | +using Syncfusion.Maui.Core; |
| 59 | +. . . |
| 60 | + |
| 61 | + using Syncfusion.Maui.Buttons; |
| 62 | + namespace RadioButtonGettingStarted |
| 63 | + { |
| 64 | + public partial class MainPage : ContentPage |
| 65 | + { |
| 66 | + public MainPage() |
| 67 | + { |
| 68 | + InitializeComponent(); |
| 69 | + SfRadioButton radioButton = new SfRadioButton(); |
| 70 | + this.Content=radioButton |
| 71 | + } |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | +``` |
| 76 | + |
| 77 | +## Change the Radio Button state |
| 78 | + |
| 79 | +The two different visual states of the [.NET MAUI Radio Button](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Buttons.SfRadioButton.html) are: |
| 80 | + |
| 81 | +* Checked |
| 82 | +* Unchecked |
| 83 | + |
| 84 | +To change the state of the .NET MAUI Radio Button, you can utilize the [IsChecked](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Buttons.SfRadioButton.html#Syncfusion_Maui_Buttons_SfRadioButton_IsChecked) property of [SfRadioButton](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Buttons.SfRadioButton.html). When the Radio Button is checked, an inner circle is added to its visualization. |
| 85 | + |
| 86 | +You can group multiple Radio Buttons together by using Radio Group. Only one button within a group can be selected at a time. |
| 87 | + |
| 88 | +**XAML** |
| 89 | +``` |
| 90 | + <buttons:SfRadioGroup x:Name="radioGroup"> |
| 91 | + <buttons:SfRadioButton x:Name="male" Text="Male"/> |
| 92 | + <buttons:SfRadioButton x:Name="female" Text="Female" IsChecked="True"/> |
| 93 | + </buttons:SfRadioGroup> |
| 94 | +``` |
| 95 | + |
| 96 | +**C#** |
| 97 | +``` |
| 98 | + SfRadioGroup radioGroup = new SfRadioGroup(); |
| 99 | + SfRadioButton male = new SfRadioButton(); |
| 100 | + male.Text = "Male"; |
| 101 | + SfRadioButton female = new SfRadioButton(); |
| 102 | + female.IsChecked = true; |
| 103 | + female.Text = "Female"; |
| 104 | + radioGroup.Children.Add(male); |
| 105 | + radioGroup.Children.Add(female); |
| 106 | + this.Content = radioGroup; |
| 107 | +``` |
| 108 | +Run the application to render the following output: |
| 109 | + |
| 110 | + |
0 commit comments