views:

131

answers:

2

I can't believe I'm back to this after working with WPF for 3 months :)

Consider very common setup:

How do I configure the rowheights so that the top and bottom rows (menu bar and status bar) size to fit the height of their content, and the middle row (main content), fills the remaining available space in the program?

I can't fix the height of the top/bottom rows because the height of their content can vary.

<Window>
  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition/>
      <RowDefinition/>
       <RowDefinition/>
    </Grid.RowDefinitions>

  <Menu Grid.Row=0>
  ...menuitems
  </Menu>

      <Grid Grid.Row=1>
       ...main application content here (like most programs)
      </Grid>

      <StatusBar>
      ...statusbaritems
      </StatusBar>
   </Grid>
</Window>
+3  A: 

You use:

<Grid.RowDefinitions>
    <RowDefinition Height="Auto" />
    <RowDefinition Height="*" />
    <RowDefinition Height="Auto" />
</Grid.RowDefinitions>

Auto will size to content, and * will fill space. If you had multiple "content" areas in between, you can use multiples, too:

<Grid.RowDefinitions>
    <RowDefinition Height="Auto" />
    <RowDefinition Height="2*" /> <!-- Will be 2/3rd of main space -->
    <RowDefinition Height="1*" /> <!-- Will be 1/3rd of main space -->
    <RowDefinition Height="Auto" />
</Grid.RowDefinitions>
Reed Copsey
+3  A: 
<Grid.RowDefinitions>
  <RowDefinition Height="Auto" />
  <RowDefinition Height="*" />
  <RowDefinition Height="Auto" />
</Grid.RowDefinitions>

From GridUnitType Enumeration:

Auto: The size is determined by the size properties of the content object.
Star: The value is expressed as a weighted proportion of available space.

Heinzi
Thanks!As it turns out, I had an image in the statusbar set to "hidden," and it's default was to fill it's available area. That's why my bottom row kept taking up 90% of the screen! :) Once i resolved that, your solution worked perfectly.
Matt H.