wpf容器
1.Grid
1.1定义行和列
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="2*"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
</Grid>
1.2.定义高度
1.2.1 ,固定高度
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition/>
</Grid.RowDefinitions>
1.2.2 按照比例,相当于整个Grid分三分,第一行占两份
<Grid.RowDefinitions>
<RowDefinition Height="2*"/>
<RowDefinition/>
</Grid.RowDefinitions>

1.2.3.自动设置,如何第一行没有内容,auto就是行高在没有内容时会塌缩为 0 。
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
1.2.4.跨行/跨列

2.StackPanel和WrapPanel:最大的区别是StackPane不会自动换行或者列,可能会挡住,WrapPanel会自动换行或者列;

3.DockPanel:
如果什么都不设,最后一个元素会默认填充剩余空间,因为有了宽高,所以最后一个元素居中了;可通过LastChildFill=“False”,取消填充

可以停靠:

5.UniformGrid:可自定义行数和列数

6.布局设计:

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border Background="Blue"/>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Border Background="Red"/>
<Grid Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="0.8*"/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Border Background="Yellow"/>
<Border Grid.Row="0" Grid.Column="1" Background="Red"/>
<Border Grid.Row="0" Grid.Column="2" Background="Yellow"/>
<Border Grid.Row="0" Grid.Column="3" Background="Red"/>
<Border Grid.Row="0" Grid.Column="4" Background="Yellow"/>
<Border Grid.Row="1" Grid.Column="0" Grid.RowSpan="1" Grid.ColumnSpan="3" Background="Blue"/>
<Border Grid.Row="1" Grid.Column="3" Grid.RowSpan="1" Grid.ColumnSpan="3" Background="Yellow"/>
<Border Grid.Row="2" Grid.Column="0" Grid.RowSpan="1" Grid.ColumnSpan="3" Background="Red"/>
<Border Grid.Row="3" Grid.Column="3" Grid.RowSpan="1" Grid.ColumnSpan="3" Background="Blue"/>
</Grid>
</Grid>
</Grid>

浙公网安备 33010602011771号