能见度="折叠"对网格中的GroupBoxes没有影响

时间:2015-05-19 14:10:04

标签: wpf xaml

我有一个带有网格和不同组框的视图。将第一行中所有组框的可见性设置为Collapsed应该让它们消失(有效)并制作"空格"对于下面的组合框。他们应该向上移动(这不起作用):

<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">

    <Grid Height="Auto" Name="Top">
        <Grid.RowDefinitions>
            <RowDefinition Height="1*" />
            <RowDefinition Height="1*" />
        </Grid.RowDefinitions>
        <Grid Grid.Row="0">
            <Grid.RowDefinitions>
                <RowDefinition Height="1*" />
                <RowDefinition Height="1*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1*" />
                <ColumnDefinition Width="1*" />
            </Grid.ColumnDefinitions>
            <GroupBox Grid.Row="0" Grid.Column="0" Header="GroupBox 1" Visibility="Collapsed">
                <Label Content="It (doesn't) work (1)"/>
            </GroupBox>
            <GroupBox Grid.Row="0" Grid.Column="1" Header="GroupBox 2" Visibility="Collapsed">
                <Label Content="It (doesn't) work (2)"/>
            </GroupBox>
            <GroupBox Grid.Row="1" Grid.Column="0" Header="GroupBox 3">
                <Label Content="It (doesn't) work (3)"/>
            </GroupBox>
            <GroupBox Grid.Row="1" Grid.Column="1" Header="GroupBox 4">
                <Label Content="It (doesn't) work (4)"/>
            </GroupBox>
        </Grid>
        <Grid Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="1*" />
                <RowDefinition Height="1*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1*" />
                <ColumnDefinition Width="1*" />
                <ColumnDefinition Width="1*" />
            </Grid.ColumnDefinitions>
            <GroupBox Grid.Row="0" Grid.Column="0" Header="GroupBox 5">
                <Label Content="It (doesn't) work (5)"/>
            </GroupBox>
            <GroupBox Grid.Row="0" Grid.Column="1" Header="GroupBox 6">
                <Label Content="It (doesn't) work (6)"/>
            </GroupBox>
            <GroupBox Grid.Row="0" Grid.Column="2" Header="GroupBox 7">
                <Label Content="It (doesn't) work (7)"/>
            </GroupBox>
            <GroupBox Grid.Row="1" Grid.Column="0" Header="GroupBox 8">
                <Label Content="It (doesn't) work (8)"/>
            </GroupBox>
            <GroupBox Grid.Row="1" Grid.Column="1" Header="GroupBox 9">
                <Label Content="It (doesn't) work (9)"/>
            </GroupBox>
            <GroupBox Grid.Row="1" Grid.Column="2" Header="GroupBox 2">
                <Label Content="It (doesn't) work (10)"/>
            </GroupBox>
        </Grid>
    </Grid>
</Window>

所以现在我的视图顶部有很多空间。我的错误在哪里?

2 个答案:

答案 0 :(得分:1)

您使用Height="1*"指定行定义。这会在行间均匀分割高度。折叠行的内容不会影响它们的高度。

如果您希望根据内容调整行大小,则应使用Height="auto"

答案 1 :(得分:0)

问题是您的行和列具有固定的高度和宽度。它们都没有设置为Auto