我正在使用 GridSplitter 来调整网格中单元格的大小,但是它的行为不是我所期望的,我找不到解决方案。它是一个三行网格,第一行的行定义设置为 Auto 并包含一些元素。第二行有一些数据,并有一个行定义 * 来填充剩余空间。最后一行是需要调整大小的状态栏,因此其中有一个网格拆分器,行定义高度为 Auto 和 MinHeight 为 30。
问题是当您将 GridSplitter 一直拖到顶部时,它会使单元格溢出。我希望它一旦到达顶部就停止。可以通过从最后一行删除 Height=Auto 来实现所需的行为,但这会使底部单元格扩展到与中间行相等的高度。
这是一个 XAML Pad 示例。
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
<Grid ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" MinHeight="20" />
<RowDefinition Height="Auto" MinHeight="30" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="Foo" />
<TextBlock Grid.Row="1" Text="Bar" />
<GridSplitter Canvas.ZIndex="1" VerticalAlignment="Top" Grid.Row="2" Background="Cyan" Height="5" HorizontalAlignment="Stretch" />
<TextBlock VerticalAlignment="Bottom" Grid.Row="2" TextWrapping="Wrap">LOL<LineBreak/>LOL<LineBreak/>LOL</TextBlock>
</Grid>
</Page>
当您拖动到顶部时,您会注意到底部的文本消失了。
我尝试了各种方法,例如将网格拆分器放在它自己的单元格中,以及将高度绑定到另一个对象 ActualHeight 等,但没有一个真的能很好地工作。
我知道这不是解释得最好的问题,但任何想法都会非常感激。
编辑: 我已经用自己的行制作了 GridSplitter,如下所示,但正如我之前提到的,问题仍然存在。我在这里也设置了 ResizeBehavior 和 ResizeDirection。
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
<Grid ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" MinHeight="20" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" MinHeight="30" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="Foo" />
<TextBlock Grid.Row="1" Text="Bar" />
<GridSplitter ResizeDirection="Rows" ResizeBehavior="PreviousAndNext" Grid.Row="2" Background="Cyan" Height="5" HorizontalAlignment="Stretch" />
<TextBlock VerticalAlignment="Bottom" Grid.Row="3" TextWrapping="Wrap">LOL<LineBreak/>LOL<LineBreak/>LOL</TextBlock>
</Grid>
</Page>
一个有效的例子是删除最后一行 Height="Auto" 并将其更改为 * 像这样
然而,这使得最后一行的大小等于它之前的行,而不是请求的单元格大小。