2010-03-31 223 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>