垂直GridSplitter无法调整大小

时间:2014-08-09 23:36:05

标签: c# wpf xaml

我正在尝试制作一个可以调整网格中行数的GridSplitter。 Grid由三行组成,每一行都有一个StackPanel,它包含两个标签(名称,姓氏,年龄):

<Grid Background="LightGray">
    <Grid.ColumnDefinitions>
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
        <RowDefinition />
    </Grid.RowDefinitions>
    <GridSplitter Grid.Row="0" Grid.Column="0" Height="5" 
                  VerticalAlignment="Center"
                  HorizontalAlignment="Stretch" ResizeDirection="Rows"/>
    <StackPanel Orientation="Horizontal" Grid.Row="0">
        <Label FontSize="25" Margin="10">Name</Label>
        <Label x:Name="nameLabel" FontSize="25" Margin="10"></Label>
    </StackPanel>
    <StackPanel Orientation="Horizontal" Grid.Row="1">
        <Label FontSize="25" Margin="10">Surname</Label>
        <Label x:Name="surnameLabel" FontSize="25" Margin="10"></Label>
    </StackPanel>
    <StackPanel Orientation="Horizontal" Grid.Row="2">
        <Label FontSize="25" Margin="10">Age</Label>
        <Label x:Name="ageLabel" FontSize="25" Margin="10"></Label>
    </StackPanel>
</Grid>

使用此代码,第一行不可调整大小。我看到了GridSplitter,当我将鼠标移过它时我也看到了箭头,但是如果我拖动它就不会调整行的大小。

enter image description here

2 个答案:

答案 0 :(得分:2)

我通常将GridSplitter放在自己的GridRow中。这将为您带来理想的效果:

<Grid Background="LightGray">
    <Grid.ColumnDefinitions>
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition Height="Auto" />
        <RowDefinition />
        <RowDefinition />
    </Grid.RowDefinitions>
    <StackPanel Orientation="Horizontal" Grid.Row="0">
        <Label FontSize="25" Margin="10">Name</Label>
        <Label x:Name="nameLabel" FontSize="25" Margin="10"></Label>
    </StackPanel>
    <GridSplitter Grid.Row="1" Grid.Column="0" Height="5"
                  HorizontalAlignment="Stretch" />
    <StackPanel Orientation="Horizontal" Grid.Row="2">
        <Label FontSize="25" Margin="10">Surname</Label>
        <Label x:Name="surnameLabel" FontSize="25" Margin="10"></Label>
    </StackPanel>
    <StackPanel Orientation="Horizontal" Grid.Row="3">
        <Label FontSize="25" Margin="10">Age</Label>
        <Label x:Name="ageLabel" FontSize="25" Margin="10"></Label>
    </StackPanel>
</Grid>

答案 1 :(得分:1)

尝试将GridSplitter&#39; VerticalAlignment设为"Bottom"