2
<DockPanel>           
      <TreeView DockPanel.Dock="Bottom" />
      <DataGrid DockPanel.Dock="Bottom" Visibility="Collapsed"/>
</DockPanel>

Basically I want the first TreeView to fill the remaining space that the second DataGrid takes up when he's "collapsed".

And if I were to set the first TreeView to "Collapsed", I want the second one to grow in height when its set to Visible.

This doesnt work due to LastChildFill. But even if I set it to false, I cant get the elements to fit properly when one is collapsed. I cannot use a stackpanel here, as the stackpanel ignores free space entirely within the control, so it never fills my window!

user99999991
  • 1,351
  • 3
  • 19
  • 43
  • Remove all those ScrollViewers. Both `DataGrid` and `TreeView` have a ScrollViewer inside their default `ControlTemplate`. You will badly break your UI like this. Other than that, have a look at [WPF Layout Tutorial](http://www.codeproject.com/Articles/140613/WPF-Tutorial-Layout-Panels-Containers-Layout-Trans). – Federico Berasategui Jul 24 '14 at 22:07
  • Thanks! Quite right about the ScrollViewers. But, that page doesnt solve anything related to my issue about have the 2 controls, hiding one and letting the other be visible while filling up the space to resize. A stack panel doesnt work here because I need the whole thing filled. – user99999991 Jul 24 '14 at 22:19
  • 1
    My WPF is getting a bit rusty, but can't you use a `Grid` with two rows both with height set to `*`. When one is collapsed the other would fill, and when neither is collapsed they would share evenly? – CodingGorilla Jul 24 '14 at 22:33
  • Try an `UniformGrid` with a single column and with the treeview and the datagrid being its children - but you need to check if the resulting 50%/50% height of the treeview and datagrid will be according to your desires/requirement. However, if your intention is to eventually allow the user to resize the arrangement of these two controls with a splitter, you should use a Grid (but you would then need to implement some logic to rearrange layout and the grid's splitter control in case one of the children is collapsed) –  Jul 24 '14 at 22:47

1 Answers1

2

I used

<DockPanel>
      <Grid>
          <TreeView DockPanel.Dock="Bottom" />
          <DataGrid DockPanel.Dock="Bottom" Visibility="Collapsed"/>
      </Grid>
</DockPanel>

And I toggle the Visibility of DataGrid and TreeView when I want to swap. The Grid didn't occur to me because I didn't think the Grid would take the shape of the window. If you did this alone without DockPanel, you'd get a datagrid that would go out into infinity off screen. But the DockPanel applies "LastFillChild" to Grid, and inherently, the children.

user99999991
  • 1,351
  • 3
  • 19
  • 43