The .NET Multi-platform App UI (.NET MAUI) RadioButton is a type of button that allows users to select one option from a set. Each option is represented by one radio button, and you can only select one radio button in a group.
new VStack(spacing: 5)
{
new RadioButton("Radio 1"),
new RadioButton("Radio 2"),
new RadioButton("Radio 3"),
new RadioButton("Radio 4")
.IsChecked(true)
},
Group of radio buttons with custom content
new VStack
{
new RadioButton
{
new Image("icon_email.png")
},
new RadioButton
{
new Image("icon_lock.png")
}
}
On Android, you must define a ControlTemplate to show custom content for the radio button.
This code enumerates its values and displays them in a button group:
public VisualNode RadioButtonsEnum<T>() where T : struct, System.Enum
{
return new VStack
{
Enum.GetValues<T>()
.Select(_=> new RadioButton(_.ToString()))
};
}