[WinUI 3][RadioButton] グループ化した RadioButton にチェックを付ける

スポンサーリンク

この記事では グループ化した RadioButton にチェックを付ける方法について説明をします。

環境

開発環境 Microsoft Visual Studio Enterprise 2019
Version 16.11.5
Framework Microsoft .NET Framework Version 4.8.04161

グループ化した RadioButton にチェックを付ける

<RadioButtons> を使用することで、複数の RadioButton をグループ化することができますが、チェックを付ける場合は <RadioButtons> が持つ  SelectedIndex プロパティを使用します。
XAML の例

<Window
    x:Class="WinUISample.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:WinUISample"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
        <TextBlock Text="果物" />
        <RadioButtons x:Name="myRadioButtons" SelectedIndex="1">
            <x:String>リンゴ</x:String>
            <x:String>ミカン</x:String>
            <x:String>バナナ</x:String>
        </RadioButtons>
    </StackPanel>
</Window>

C# の例

public MainWindow()
{
    this.InitializeComponent();
    myRadioButtons.SelectedIndex = 1;
}
グループ化したラジオボタンにチェックを付ける例

グループ化したラジオボタンにチェックを付ける例

WinUi Tips

本サイトでまとめている WinUI Tips の一覧はこちらから確認できます。

Please follow and like us:

コメント

タイトルとURLをコピーしました