1

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. (1) start (2) problem
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. (1) start (2) problem (3) target

Any suggestions?

senfen
  • 877
  • 5
  • 21
  • The behaviors you've listed sound more like a dockpanel. Could you use a border inside of a dockpanel? – Felix Castor May 05 '18 at 22:40
  • How can I achieve behavior of GridSplitter with DockPanel? This setting allows me to manually control share ratio of DataGrid and TextBox. Without GridSplitter feature it will behave like simple DockPanel. I saw that there is some online solution for 'DockPanelSplitter' but I would like to use build-in WPF mechanism. – senfen May 05 '18 at 23:54

0 Answers0