wpf 如何将网格行拆分为两列?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9040535/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to split a Grid row into two columns?
提问by GANI
I have the Grid layout with 3 rows.How do i split the 3rd row into 2 columns.
我有 3 行的网格布局。如何将第 3 行拆分为 2 列。
<Grid.RowDefinitions>
<RowDefinition Height="0.75*"/>
<RowDefinition Height="0.25*"/>
<RowDefinition Height="36"/>
</Grid.RowDefinitions>
回答by Joe White
Two ways you can do it:
有两种方法可以做到:
Use nested layouts. Put another
Grid
in the third row, and have two columns in that sub-grid.<Grid> <Grid.RowDefinitions> ... </Grid.RowDefinitions> <ThingInFirstRow Grid.Row="0" /> <ThingInSecondRow Grid.Row="1" /> <Grid Grid.Row="2"> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition /> </Grid.ColumnDefinitions> <ThingInLowerLeft Grid.Column="0" /> <ThingInLowerRight Grid.Column="0" /> </Grid> </Grid>
Stick with one
Grid
, give it two columns, and make the things in the first two rows span across both columns usingColumnSpan
.<Grid> <Grid.RowDefinitions> ... </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition /> </Grid.ColumnDefinitions> <ThingInFirstRow Grid.Row="0" Grid.ColumnSpan="2" /> <ThingInSecondRow Grid.Row="1" Grid.ColumnSpan="2" /> <ThingInLowerLeft Grid.Row="2" Grid.Column="0" /> <ThingInLowerRight Grid.Row="2" Grid.Column="1" /> </Grid>
使用嵌套布局。将另一个
Grid
放在第三行,并在该子网格中有两列。<Grid> <Grid.RowDefinitions> ... </Grid.RowDefinitions> <ThingInFirstRow Grid.Row="0" /> <ThingInSecondRow Grid.Row="1" /> <Grid Grid.Row="2"> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition /> </Grid.ColumnDefinitions> <ThingInLowerLeft Grid.Column="0" /> <ThingInLowerRight Grid.Column="0" /> </Grid> </Grid>
坚持使用 one
Grid
,给它两列,并使用 使前两行中的内容跨越两列ColumnSpan
。<Grid> <Grid.RowDefinitions> ... </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition /> </Grid.ColumnDefinitions> <ThingInFirstRow Grid.Row="0" Grid.ColumnSpan="2" /> <ThingInSecondRow Grid.Row="1" Grid.ColumnSpan="2" /> <ThingInLowerLeft Grid.Row="2" Grid.Column="0" /> <ThingInLowerRight Grid.Row="2" Grid.Column="1" /> </Grid>