2016-02-05 48 views
1

我有5列(1和5相同大小,2和4相同大小)的佈局:不同大小「優先級」的網格列

| 1 | 2 | 3 | 4 | 5 |

我們允許用戶水平調整應用程序(它收縮),我試圖達到的行爲如下:收縮列1和5,直到他們消失

| 1 | 2 | 3 | 4 | 5 |

|| 2 | 3 | 4 ||

| 2 | 3 | 4 |

然後才把,開始萎縮2和4,直到最小寬度(3始終保持相同大小)

我與單個網格和嵌套網格嘗試這樣做也但我不能重現預期的行爲。就像tittle說的那樣,我想優先考慮哪些列首先縮小。

回答

1

可以生產,使用三個光柵

<Grid> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="*"/> 
     <ColumnDefinition Width="Auto"/> 
     <ColumnDefinition Width="*"/> 
    </Grid.ColumnDefinitions> 
    <Grid x:Name="Grid1" Grid.Column="0"> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="*"/> 
      <ColumnDefinition Width="Auto"/> 
     </Grid.ColumnDefinitions>    
     <Rectangle Fill="LightBlue" Grid.Column="0" Width="200"/> 
     <Rectangle Fill="LightGreen" Grid.Column="1" Width="100"/> 
    </Grid> 

     <Grid x:Name="Grid3" Grid.Column="1"> 
      <Rectangle Fill="Black" Width="100"/> 
     </Grid> 

    <Grid x:Name="Grid5" Grid.Column="2"> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="Auto"/> 
      <ColumnDefinition Width="*"/> 
     </Grid.ColumnDefinitions> 
     <Rectangle Fill="LightGreen" Grid.Column="0" Width="100"/> 
     <Rectangle Fill="LightBlue" Grid.Column="1" Width="200"/> 
    </Grid> 
</Grid> 

The Result

+1

好樣的!很好的答案(+1)^^ –

+1

哇,甚至添加了一個gif。你是男人! –

0

這裏是例子。

<Grid> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="*" /> 
     <ColumnDefinition Width="1000*" MaxWidth="300" /> 
     <ColumnDefinition Width="*" /> 
    </Grid.ColumnDefinitions> 
    <Grid Grid.Column="0" Background="White" /> 
    <Grid Grid.Column="2" Background="White" /> 
    <Grid Grid.Column="1"> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="*" /> 
      <ColumnDefinition Width="1000*" MaxWidth="100" /> 
      <ColumnDefinition Width="*" /> 
     </Grid.ColumnDefinitions> 
     <Grid Grid.Column="0" Background="PaleGreen" /> 
     <Grid Grid.Column="2" Background="PaleGreen" /> 
     <Grid Grid.Column="1" Background="WhiteSmoke" /> 
    </Grid> 
</Grid>