我找到了答案 - 我不知道它是否是 WPF 错误,或者我没有正确阅读文档
<Border Background="Red" HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBox Text="123" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" />
<TextBox Text="123" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" />
<TextBox Text="123" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" />
<TextBox Text="123" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" />
<TextBox Text="123" Grid.Row="2" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" Visibility="Collapsed" />
<TextBox Text="123" Grid.Row="2" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Visibility="Collapsed" />
</Grid>
</Border>
如果您查看代码,您会看到有 3 个星号 (*) 大小的行,它们应该在网格的高度中占有相等的份额,而不管它们的内容如何。
但是,当您折叠分配给该行的所有内容时,该行本身也会折叠。(如果你窥探它,它的高度为 *,但 ActualHeight 为 0)
有人认为这是正常行为吗?在过去 5 年的所有 WPF 开发中,我从未听说过这一点