概要
この記事では、WPFのRadioButtonコントロールを垂直方向に配置する方法について説明します。
構文
RadioButtonを垂直方向に配置するためには、StackPanelやGridなどのコンテナ要素を使用します。以下に構文の例を示します。
<StackPanel Orientation="Vertical">
<RadioButton Content="選択肢1" />
<RadioButton Content="選択肢2" />
<RadioButton Content="選択肢3" />
</StackPanel>
上記の例では、StackPanelのOrientationプロパティを”Vertical”に設定しています。これにより、RadioButtonが垂直方向に配置されます。
使用例
以下に、垂直に配置されたRadioButtonの画面デザインを表すXAMLコードとコードビハインドの例を示します。
XAMLコード:
<StackPanel Orientation="Vertical">
<RadioButton Content="オプション1" />
<RadioButton Content="オプション2" />
<RadioButton Content="オプション3" />
</StackPanel>
コードビハインドの例:
private void RadioButton_Checked(object sender, RoutedEventArgs e)
{
// ラジオボタンが選択された時の処理
}
上記の例では、”オプション1″、”オプション2″、”オプション3″のRadioButtonが垂直に並びます。また、コードビハインドではRadioButtonのCheckedイベントを処理する方法を示しています。
Please follow and like us:


コメント