【发布时间】:2016-04-26 04:31:51
【问题描述】:
我有一些理解上的问题。我在 WPF 中有一个Grid,具有交替的固定行高和自动行高。
如果我将Label 添加到第一列中具有自动高度的行,那么这将按我的预期工作。
但是,如果我在第 1 列中添加一个带有 RowSpan 的控件,则调整大小的不是具有自动高度的行,而是调整了具有固定高度的行。
看看这个例子:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="5" />
<RowDefinition Height="Auto" />
<RowDefinition Height="5" />
<RowDefinition Height="Auto" />
<RowDefinition Height="5" />
<RowDefinition Height="Auto" />
<RowDefinition Height="5" />
<RowDefinition Height="Auto" />
<RowDefinition Height="5" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="150" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Grid.Row="1"
Grid.Column="0"
Content="Label1" />
<Label Grid.Row="3"
Grid.Column="0"
Content="Label2" />
<Label Grid.Row="5"
Grid.Column="0"
Content="Label3" />
<Label Grid.Row="7"
Grid.Column="0"
Content="Label4" />
<Border Grid.Row="1"
Grid.RowSpan="7"
Grid.Column="1"
Height="300"
Background="Red" />
<!--<Label Grid.Row="2"
Grid.Column="0"
Content="Hallo" />-->
</Grid>
如果我在固定标签上添加标签也不合逻辑,因为我看不到这个标签,因为尺寸 5 太小了。尽管该行显示得更大。
【问题讨论】:
-
只是不要设置Border的
Height。 -
您描述的行为也不是我所预料的,似乎“自动”被保留以支持固定高度 - 奇怪!