views:

115

answers:

1

Say I've got two elements in a window.
I'd like element A to fill all unused vertcial space and have always at least eg. 200px height.
Element B will have few fixed sizes (expander) and it should be given the space it demands (but leaving at least 200px for A). If there is not enough free space in a window, B should be scrollable.

That's close to what I wan't to achive, but DockPanel doesn't respect MinHeight property.

<DockPanel>
  <ScrollViewer DockPanel.Dock="Bottom">
    <B/>
  </ScrollViewer>
  <A MinHeight="200"/>
</DockPanel>

Is there any way to do it using WPF native panels?

+2  A: 

A DockPanel will always process the panels in the order they are defined in; it won't make a docked element smaller just because the last element has a MinHeight.

I would use a Grid:

<Grid>
  <Grid.RowDefinitions>
    <RowDefinition Height="*" MinHeight="200" />
    <RowDefinition Height="Auto" />
  </Grid.RowDefinitions>
  <A Grid.Row="0"/>
  <ScrollViewer Grid.Row="1">
    <B/>
  </ScrollViewer>
</Grid>
Daniel
This wouldn't work. It doesn't correspond to original requirement " If there is not enough free space in a window, B should be scrollable". When you set Height to Auto, Grid gives you any size you request. So ScrollViewer will never have scrollbars until you hardcode its height.
Anvaka
As Anvaka said, that won't work.
cz_dl
You're right, the second row will be go below the containing window.There doesn't seem to be a way to say "Auto, but only if there's enough room"I guess you'll need code to do it (custom layout panel, or attaching to some event handler and setting size explicitly)
Daniel
I actually have written such panel some time ago, but can't find it now. Since it's not an especially fancy scenario (some list + details pane in resizable window!), I've thought that maybe I'm missing something obvious, but have to start coding back, I see.
cz_dl