Reputation: 21966
I'm trying to make a GridSplitter which can resize rows in a Grid. The Grid is made of three rows, each one has a StackPanel which contains two labels (name, surname, age):
<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>
With this code the first row isn't resizable. I see the GridSplitter, and I also see the arrow when I pass the mouse over it, but if I drag it the row doesn't get resized.
Upvotes: 0
Views: 696
Reputation: 66449
I usually place the GridSplitter
in its own GridRow
. This will give you the desired effect:
<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>
Upvotes: 2