2010-03-31 108 views
2

我不能相信我回来这与WPF工作了3个月后:)简单的网格布局问题

考虑很常见的设置:

如何配置rowHeights中,使顶和底部行(菜单栏和状态栏)大小以适应其内容的高度,并在中间行(主要内容)填充程序中剩余的可用空间?

我无法修复顶部/底部行的高度,因为它们的内容高度可能会有所不同。

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

回答

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

GridUnitType Enumeration

自动:大小由内容的大小属性决定目的。
星级:该值表示为可用空间的加权比例。

+0

谢谢! 事实证明,我将状态栏中的图像设置为“隐藏”,并且它的默认设置是填充可用区域。这就是为什么我的底排继续占据屏幕的90%! :)一旦我解决了这个问题,你的解决方案就完美了 – 2010-03-31 20:33:10

3

您使用:

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

自动将大小的内容,以及*将填补空间。如果你在两者之间有多个“内容”区域,您可以使用倍数,太:

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