Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set initial height of a GridSplitter 'pane'?

I am using a GridSplitter in my WPF Window. Above the splitter is a TreeView, below is a DockPanel containing amongst other things a textbox. When I select an item in the TreeView, the DockPanel's contents are updated via data-binding.

Depending on the content of the TextBox, the lower pane of the Window expands and contracts in size. I want it to start at Height X, and stay at that Height unless the GridSplitter is dragged by the user.

I tried setting the Height of the lower DockPanel in the XAML, but this fixes the height of the DockPanel so that it doesn't resize when the GridSplitter is moved. Maybe the solution involves the Grid.Row Heights?

Here's the general structure of my page.

Window
  Grid
    row1 Height="*":    TreeView
    row2 Height="5":    GridSplitter
    row3 Height="auto": DockPanel  // gets taller and shorter depending on its content.
      ...
      TextBox

BTW: after I've dragged the GridSplitter, the resizing stops happening and the UI behaves how I want it to.

like image 501
mackenir Avatar asked Apr 14 '11 12:04

mackenir


1 Answers

Explicitly set the Height of the grid-row that you want to have an initial size.

Right now row3 is on Auto and resizes to content, as soon as you drag the GridSplitter that value is being replaced by the current height of the row.

like image 191
H.B. Avatar answered Nov 09 '22 01:11

H.B.