开发者

Simple grid layout question

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>


<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.


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜