合并网格列

时间:2014-05-21 17:05:04

标签: c# wpf xaml grid

您好我一直在寻找一个没有成功的解决方案......

我想要一个类似于:

的网格
+-------+----------------+
|       |                |
+-------+----------------+
|                        |
|                        |
|                        |
+-------+----------------+
|       |                |        
+-------+----------------+

提前谢谢!

2 个答案:

答案 0 :(得分:26)

它看起来像一个3行,2列网格,比例大小:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="2*" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="3*" />
    </Grid.ColumnDefinitions>
</Grid>

5个细胞就像:

  • 左上角:Grid.Column =“0”,Grid.Row =“0”
  • 右上角:Grid.Column =“1”,Grid.Row =“0”
  • 中心:Grid.Column =“0”,Grid.Row =“1”,Grid.ColumnSpan =“2”
  • 左下角:Grid.Column =“0”,Grid.Row =“2”
  • 右下角:Grid.Column =“1”,Grid.Row =“2”

答案 1 :(得分:12)

现在,这是一个非常简单的网格。两列和三行,第二行内容跨越两列...它没有比那简单得多......

  <Grid Width="640" Height="480">  
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="3*"/>
      <ColumnDefinition Width="7*"/>  
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
      <RowDefinition Height="25*"/>
      <RowDefinition Height="50*"/>
      <RowDefinition Height="25*"/>
    </Grid.RowDefinitions>
  <Border Grid.Column="0" Grid.Row="0" BorderBrush="Red" Margin="1" BorderThickness="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
  <Border Grid.Column="1" Grid.Row="0" BorderBrush="Green" Margin="1" BorderThickness="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
  <Border Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2" Margin="1" BorderThickness="2" BorderBrush="Blue" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
  <Border Grid.Column="0" Grid.Row="2" BorderBrush="Red" Margin="1" BorderThickness="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
  <Border Grid.Column="1" Grid.Row="2" BorderBrush="Green" Margin="1" BorderThickness="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
  </Grid>

enter image description here