UniformGrid中奇怪的元素间距

时间:2016-10-10 10:53:47

标签: c# wpf

到目前为止,我有一个相当简单的设置,如下所示:

enter image description here

正如你所看到的,3号看起来非常好。然而另外两个则没有。我有以下代码:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>
    <StackPanel Grid.Row="0" Orientation="Vertical" Margin="0,0,5,0" Background="#FFEAEAEA">
        <GroupBox x:Name="playStyleBox" Header="1. Play Style" HorizontalAlignment="Left" Margin="10,0,10,0" VerticalAlignment="Top">
            <UniformGrid Columns="4">
                <CheckBox x:Name="CheckBoxSubtle">Subtle</CheckBox>
                <CheckBox x:Name="CheckBoxBalanced">Balanced</CheckBox>
                <CheckBox x:Name="CheckBoxAggressive">Aggressive</CheckBox>
                <CheckBox x:Name="CheckBoxSupportive">Supportive</CheckBox>
            </UniformGrid>
        </GroupBox>
        <GroupBox x:Name="playStyleSubBox" Header="2. Sub Play Style" HorizontalAlignment="Left" Margin="10,0,10,0" VerticalAlignment="Top">
            <UniformGrid Columns="3">
                <CheckBox x:Name="CheckBoxMelee">Melee</CheckBox>
                <CheckBox x:Name="CheckBoxRanged">Ranged</CheckBox>
                <CheckBox x:Name="CheckBoxMagic">Magic</CheckBox>
            </UniformGrid>
        </GroupBox>
        <GroupBox x:Name="alignmentBox" Header="3. Alignment" HorizontalAlignment="Left" Margin="10,0,5,0" VerticalAlignment="Top">
            <UniformGrid Columns="3">
                <CheckBox x:Name="CheckBoxLawfulGood">Lawful Good</CheckBox>
                <CheckBox x:Name="CheckBoxNeutralGood">Neutral Good</CheckBox>
                <CheckBox x:Name="CheckBoxChaoticGood">Chaotic Good</CheckBox>
                <CheckBox x:Name="CheckBoxLawfulNeutral">Lawful Neutral</CheckBox>
                <CheckBox x:Name="CheckBoxNeutral">Neutral</CheckBox>
                <CheckBox x:Name="CheckBoxChaoticNeutral">Chaotic Neutral</CheckBox>
                <CheckBox x:Name="CheckBoxLawfulEvil">Lawful Evil</CheckBox>
                <CheckBox x:Name="CheckBoxNeutralEvil">Neutral Evil</CheckBox>
                <CheckBox x:Name="CheckBoxChaoticEvil">Chaotic Evil</CheckBox>
            </UniformGrid>
        </GroupBox>
    </StackPanel>
    <GridSplitter Grid.Column="0" Width="4" BorderBrush="Red" VerticalAlignment="Stretch">
        <GridSplitter.Template>
            <ControlTemplate TargetType="{x:Type GridSplitter}">
                <Grid>
                    <Button Content="⁞"/>
                    <Rectangle Fill="#FFACACAC"/>
                </Grid>
            </ControlTemplate>
        </GridSplitter.Template>
    </GridSplitter>
</Grid>

任何帮助将不胜感激。我很遗憾为什么这会发生在前两个UniformGrid而不是最后一个。

1 个答案:

答案 0 :(得分:1)

  1. UniformGrid创建相同大小的Columns。因此,最大控件控制Column

  2. 的大小
  3. 在所有HorizontalAlignment="Stretch"中设置Margin="10,0,10,0"GroupBox

  4. Columns的{​​{1}}的数量更改为3。