wpf - GridSplitter 未正确分割

标签 wpf xaml

我有以下网格

<Grid>        
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

我的GridSplitter位于第3行(第4行),定义如下:

<GridSplitter Grid.Row="3"
              ResizeDirection="Rows"
              Style="{StaticResource HorizontalGridSplitter}"
              IsTabStop="False" />
<Style x:Key="HorizontalGridSplitter"
       TargetType="{x:Type GridSplitter}">
    <Setter Property="Height"
            Value="4" />
    <Setter Property="HorizontalAlignment"
            Value="Stretch" />
    <Setter Property="VerticalAlignment"
            Value="Stretch" />
    <Setter Property="Margin"
            Value="0" />
</Style>

当我拖动分割线以分割第 2/4 行时,它并没有真正分割行,看起来网格高度变大了。

最佳答案

GridSplitter 具有三种不同的调整大小行为,如下所示:

Resize Behaviours

GridSplitter 根据所选的 ResizeBehaviour 以及它们的可用空间重新调整指定的两列/行的大小,在您的情况下,您指定了 * 高度之前的行和之后的行的自动高度,这意味着它只能调整之前的行的大小,之后的行将始终保持自动:

enter image description here

要解决此问题,您必须将前后行设置为 Width="*" 并将调整大小行为设置为 ResizeBehavior="PreviousAndNext" > 请参阅以下代码片段:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <GridSplitter Grid.Row="3" ResizeDirection="Rows" 
                  Style="{StaticResource HorizontalGridSplitter}"                      
                  IsTabStop="False" HorizontalAlignment="Stretch"
                  ResizeBehavior="PreviousAndNext" />
</Grid>

最好将所有其他行的高度设置为自动或固定值以避免任何奇怪的行为:)

关于wpf - GridSplitter 未正确分割,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5654467/

相关文章:

c# - 如何在 WPF 图表中为 Y 轴混合指数/小数格式

WPF 可见性绑定(bind)到具有多个变量的 bool 表达式

wpf - 在扩展 WPF 工具包 PropertyGrid 中选择编辑器

c# - 在 wpf 中将 treeviewitem 显示为网格行

c# - 传入 WCF 消息后 WPF UI 未更新

WPF - 如何在水平方向的堆栈面板内右对齐文本 block ?

c# - WPF - 停止单选按钮单击消息框

wpf - DateTimePicker wpf 工具包绑定(bind)

wpf - 数据绑定(bind)到 WrapPanel 不能按预期工作

xaml - 如何使用 MVVM 将 XAML 标签与 TapGestureRecognizer 绑定(bind)?