Visual Studio/WPF > 컨트롤 > GroupBox/RadioButton > Margin 설정에 유의

운영 환경
Windows 7 Pro (32bit)
Microsoft Visual Studio 2017 Community
Sublime Text 2

@ WPF 4.5 입문 by 오타 카즈키
No.4418/9985

RadioButton 컨트롤은, 복수의 선택사항중에서 1개를 유저에게 선택해 받을 때에 사용하는 컨트롤입니다.

시도해 보았다.
GroupBox 2개를 잘 레이아웃할 수 있을지도 시도했다.

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>

좋은 웹페이지 즐겨찾기