I have a problem with my Grid
layout. I would like to have three rows (second with GridSplitter
) with behavior:
If the row with TextBox
is Collapsed
, then DataGrid
fill whole space.
If the row with TextBox
is Visible
, then TextBox
and DataGrid
share space.
If the Text
is set in TextBox
, TextBox
is not expanding Height
.
TextBox
and DataGrid
fills theirs rows.
Example xaml:
<DockPanel>
<StackPanel DockPanel.Dock="Top" Orientation="Horizontal">
<CheckBox x:Name="ShowTextBox" Content="Show TextBox"/>
<Button Content="Add text" Click="ButtonBase_OnClick"/>
</StackPanel>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="5"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Background="Aqua">
<DataGrid/>
</StackPanel>
<GridSplitter Grid.Row="1"
Height="5"
HorizontalAlignment="Stretch"
ResizeDirection="Rows"
Visibility="{Binding Path=IsChecked, ElementName=ShowTextBox, Converter={StaticResource BooleanToVisibilityConverter}}"/>
<DockPanel Grid.Row="2"
Visibility="{Binding Path=IsChecked, ElementName=ShowTextBox, Converter={StaticResource BooleanToVisibilityConverter}}">
<TextBox AcceptsReturn="True" x:Name="TextBox"
VerticalScrollBarVisibility="Visible"/>
</DockPanel>
</Grid>
</DockPanel>
Problem 1:
When I change Height
of TextBox
row and set it Collapsed
, then DataGrid
will not fill empty space.
I would like to have DataGrid
expanded to whole area.
Problem 2:
If I don't touch TextBox
row Height
and add multiple lines of text then TextBox
will expand Height
. If Height
of TextBox
row was previously changed, then no problem appear.
Any suggestions?