本記事の概要
この記事では RadioButton をグループ化する方法について説明します。
公式サイト情報はコチラを参照してください。
RadioButton のグループ
通常、1画面には1つのラジオボタングループしか置くことができません。
例えば、性別と年齢の2つのグループを配置したい場合は RadioButtonGroup.GroupName 添付プロパティ を使用してグループを作成します。
以下の例では、RadioButtonGroup.GroupName を使用し、 Gender と Generation の2つのグループを作成し、それぞれのグループの中で任意の項目にチェックを付けることを可能にします。
XAML の例
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MauiAppSample.MainPage">
<ScrollView>
<StackLayout Orientation="Horizontal" HorizontalOptions="Center">
<StackLayout RadioButtonGroup.GroupName="Gender">
<Label Text="性別" />
<RadioButton Content="男性" IsChecked="True"/>
<RadioButton Content="女性" />
</StackLayout>
<StackLayout RadioButtonGroup.GroupName="Generation">
<Label Text="性別" />
<RadioButton Content="20代" />
<RadioButton Content="30代" IsChecked="True"/>
<RadioButton Content="40代" />
</StackLayout>
</StackLayout>
</ScrollView>
</ContentPage>
.NET MAUI Tips
本サイトでまとめている .NET MAUI Tips の一覧はこちらから確認できます。
Please follow and like us:


コメント