Skip to content

Commit eeebbd4

Browse files
Added a demo for radio button
1 parent 0ab5a82 commit eeebbd4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+9151
-1
lines changed

README.md

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,110 @@
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+
![Getting started with .NET MAUI busy indicator](net-maui-radio-button.png)

RadioButtonGettingStarted/App.xaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version = "1.0" encoding = "UTF-8" ?>
2+
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:local="clr-namespace:RadioButtonGettingStarted"
5+
x:Class="RadioButtonGettingStarted.App">
6+
<Application.Resources>
7+
<ResourceDictionary>
8+
<ResourceDictionary.MergedDictionaries>
9+
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
10+
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
11+
</ResourceDictionary.MergedDictionaries>
12+
</ResourceDictionary>
13+
</Application.Resources>
14+
</Application>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace RadioButtonGettingStarted
2+
{
3+
public partial class App : Application
4+
{
5+
public App()
6+
{
7+
InitializeComponent();
8+
}
9+
10+
protected override Window CreateWindow(IActivationState? activationState)
11+
{
12+
return new Window(new AppShell());
13+
}
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<Shell
3+
x:Class="RadioButtonGettingStarted.AppShell"
4+
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
xmlns:local="clr-namespace:RadioButtonGettingStarted"
7+
Shell.FlyoutBehavior="Flyout"
8+
Title="RadioButtonGettingStarted">
9+
10+
<ShellContent
11+
Title="Home"
12+
ContentTemplate="{DataTemplate local:MainPage}"
13+
Route="MainPage" />
14+
15+
</Shell>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace RadioButtonGettingStarted
2+
{
3+
public partial class AppShell : Shell
4+
{
5+
public AppShell()
6+
{
7+
InitializeComponent();
8+
}
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:buttons="clr-namespace:Syncfusion.Maui.Buttons;assembly=Syncfusion.Maui.Buttons"
5+
x:Class="RadioButtonGettingStarted.MainPage">
6+
<buttons:SfRadioGroup x:Name="radioGroup">
7+
<buttons:SfRadioButton x:Name="male" Text="Male"/>
8+
<buttons:SfRadioButton x:Name="female" Text="Female" IsChecked="True"/>
9+
</buttons:SfRadioGroup>
10+
</ContentPage>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace RadioButtonGettingStarted
2+
{
3+
public partial class MainPage : ContentPage
4+
{
5+
public MainPage()
6+
{
7+
InitializeComponent();
8+
}
9+
}
10+
11+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Microsoft.Extensions.Logging;
2+
using Syncfusion.Maui.Core.Hosting;
3+
4+
namespace RadioButtonGettingStarted
5+
{
6+
public static class MauiProgram
7+
{
8+
public static MauiApp CreateMauiApp()
9+
{
10+
var builder = MauiApp.CreateBuilder();
11+
builder
12+
.UseMauiApp<App>()
13+
.ConfigureSyncfusionCore()
14+
.ConfigureFonts(fonts =>
15+
{
16+
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
17+
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
18+
});
19+
20+
#if DEBUG
21+
builder.Logging.AddDebug();
22+
#endif
23+
24+
return builder.Build();
25+
}
26+
}
27+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
4+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
</manifest>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Android.App;
2+
using Android.Content.PM;
3+
using Android.OS;
4+
5+
namespace RadioButtonGettingStarted
6+
{
7+
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, LaunchMode = LaunchMode.SingleTop, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
8+
public class MainActivity : MauiAppCompatActivity
9+
{
10+
}
11+
}

0 commit comments

Comments
 (0)