2014-04-03 49 views
1

我有兩個元素,我希望他們能夠最有效地共享可用空間。看看下面的XAML:網格協作共享空間

<Window x:Class="Gridtest.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="MainWindow" SizeToContent="WidthAndHeight"> 

    <Grid Height="320" Width="110" > 

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

     <ScrollViewer Grid.Row="0" VerticalScrollBarVisibility="Auto" > 
      <Border Margin="5" Background="Red" Height="200" /> 
     </ScrollViewer> 

     <ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto"> 
      <Border Margin="5" Background="Blue" Height="100" /> 
     </ScrollViewer> 

    </Grid> 
</Window> 

這是結果我之後的紅色和藍色的各種高度的組合,但我不能工作了,如果這是可能的庫存面板。對行高使用自動意味着ScrollViewer不尊重實際可用空間。最後一個例子只會在藍色的中途被截斷。

enter image description here

有什麼辦法來得到我想要的只是用股票的面板,還是我將不得不寫我自己?

回答

-1

這會給第一行的所有可用空間(後第二個獲得它所需要的最小空間):

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

這將分佈在兩行之間的空間:

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

這將按1:2的比例分配第一行和第三行之間的空閒空間(在第二行獲得所需的最小空間之後):

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

等等