可见性=“折叠"对网格中的 GroupBox 没有影响 [英] Visibility="Collapsed" has no effect with GroupBoxes in grids

查看:44
本文介绍了可见性=“折叠"对网格中的 GroupBox 没有影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a view with grids and different group boxes. Setting the visibility of all group boxes in the first row to Collapsed should let them disappear (which works) and make "space" for the group boxes below. They should move upwards (which doesn't work):

<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>

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

So there is a lot of space at the top of my view now. Where's my error?

推荐答案

您可以使用 Height="1*" 指定行定义.这将跨行均匀地划分高度.折叠行的内容不会影响它们的高度.

You specify your row definitions with Height="1*". This splits up the height evenly across the rows. Collapsing the content of the rows does not affect their height.

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

If you want your rows to resize according to the content, you should use Height="auto".

这篇关于可见性=“折叠"对网格中的 GroupBox 没有影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆