動作環境
Windows 7 Pro (32bit)
Microsoft Visual Studio 2017 Community
Sublime Text 2
@ WPF 4.5入門 by 大田一希さん
No.4418 / 9985
RadioButtonコントロールは、複数の選択肢の中から1つをユーザに選択してもらうときに使うコントロールです。
試してみた。
GroupBox2つをうまくレイアウトできるかも試した。
XAML
<Window x:Class="_170426_t0930_radioButton.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:_170426_t0930_radioButton"
mc:Ignorable="d"
Title="MainWindow" Height="400" Width="525">
<Grid RenderTransformOrigin="0.5,0.205">
<Grid.RowDefinitions>
<RowDefinition Height="238"/>
<RowDefinition Height="162"/>
</Grid.RowDefinitions>
<GroupBox Header="Group1" Grid.Row="0" Margin="10,10,307,141">
<StackPanel>
<RadioButton Content="TV1" Checked="RadioButton_Checked"/>
<RadioButton Content="Refrigerator1" Checked="RadioButton_Checked"/>
<RadioButton Content="WashingMachine1" Checked="RadioButton_Checked"/>
</StackPanel>
</GroupBox>
<GroupBox Header="Group2" Grid.Row="1" Margin="10,10,307,2">
<StackPanel>
<RadioButton Content="smartphone" Checked="RadioButton_Checked"/>
<RadioButton Content="VR" Checked="RadioButton_Checked"/>
<RadioButton Content="??" Checked="RadioButton_Checked"/>
</StackPanel>
</GroupBox>
</Grid>
</Window>
上のGroupBox用のRowDefinitionのHeightをGroupBox程度のHeightにあわせると、上のGroupBoxの表示が消えた。
GroupBoxの下側のMargin設定が大きすぎたのだ問題のようだ。
以下のように修正した。
(Group1の下側のMarginを141から20に変更)
XAML
<Window x:Class="_170426_t0930_radioButton.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:_170426_t0930_radioButton"
mc:Ignorable="d"
Title="MainWindow" Height="400" Width="525">
<Grid RenderTransformOrigin="0.5,0.205">
<Grid.RowDefinitions>
<RowDefinition Height="120"/>
<RowDefinition Height="162"/>
</Grid.RowDefinitions>
<GroupBox Header="Group1" Grid.Row="0" Margin="10,10,307,20">
<StackPanel>
<RadioButton Content="TV1" Checked="RadioButton_Checked"/>
<RadioButton Content="Refrigerator1" Checked="RadioButton_Checked"/>
<RadioButton Content="WashingMachine1" Checked="RadioButton_Checked"/>
</StackPanel>
</GroupBox>
<GroupBox Header="Group2" Grid.Row="1" Margin="10,10,307,2">
<StackPanel>
<RadioButton Content="smartphone" Checked="RadioButton_Checked"/>
<RadioButton Content="VR" Checked="RadioButton_Checked"/>
<RadioButton Content="??" Checked="RadioButton_Checked"/>
</StackPanel>
</GroupBox>
</Grid>
</Window>