wpf使用-------布局
布局
(stackPanel、WrapPanel、DockPanel、Grid、UniformGrid、Canvas)
StackPanel
从左上角开始,一个个列出来
子元素可以获得的属性:
<HorizontalAlignment> 子元素在容器内的水平定位
<VerticalAlignment>子元素在容器内的垂直定位
<Margin>元素周围添加一定的空间
<MinWIdth><MinHeight>最小尺寸(max为最大尺寸)
<width><Height>显式尺寸
<border>(可以设置background/BorderBrush和BorderThickness(显示边框用)/CornerRadius(圆角)/Padding(边框和内容间增加空间))
WrapPanel
同样以上的数据均有
个人理解:wrapPanel该容器可以看做自动换行功能的StackPanel容器
DockPanel
类似于工具栏的作用
<LastChildFill> 最后一个元素占满空间
Grid
先设置
<Grid.ColumnDefinitions> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> </Grid.RowDefinitions>
之类的将页面进行单元格分布,可在RowDefinition和ColumnDefinitions里设置长宽之类的数据,*为原长,Auto为自动设置(默认是没有大小)
具体使用单元格则为
<Button Grid.Row="1" Grid.Column="0">close</Button>
如果需要跨越2行2列,则
<Button Grid.Column="0" Grid.Row="0" Grid.RowSpan="2" Grid.ColumnSpan="2">Test</Button>
要分割窗口,用<GridSplitter>
<GridSplitter Grid.Row="0" Grid.Column="1" Grid.RowSpan="3" Width="3" VerticalAlignment="Stretch" HorizontalAlignment="Center" ShowsPreview="True" > </GridSplitter>
UniformGrid
许多WPF开发人员可能一辈子都不会用到uniformGrid
Canvas
基于坐标直接布局(非常不建议使用,在拖动窗口的时候,控件不会变化,非常影响使用)

浙公网安备 33010602011771号