WPF几种常用布局方式
2022/2/13 23:44:45
本文主要是介绍WPF几种常用布局方式,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
一、Grid(网格 ***)
(*代表重要程度,一颗星代表了解就行,三颗星代表重要)
类似于html中的Table标签
<Grid> <Grid.RowDefinitions> <RowDefinition Height="200"></RowDefinition> <RowDefinition Height="1*"></RowDefinition> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="200"></ColumnDefinition> <ColumnDefinition Width="1*"></ColumnDefinition> </Grid.ColumnDefinitions> <Button Grid.Row="0" Grid.Column="0" Background="Orange" Foreground="White" FontSize="20" Cursor="Hand"> 按钮1 </Button> <Button Grid.Row="0" Grid.Column="1" Background="Red" Foreground="White" FontSize="20" Cursor="Hand">按钮2</Button> <Button Grid.Row="1" Grid.Column="0" Background="Blue" Foreground="White" FontSize="20" Cursor="Hand">按钮3</Button> <Button Grid.Row="1" Grid.Column="1" Background="Orange" Foreground="White" FontSize="20" Cursor="Hand">按钮4</Button> </Grid>
二、StackPanel(***)
<StackPanel Orientation="Vertical"> <Button Background="Orange" Foreground="White" FontSize="20" Cursor="Hand">按钮1</Button> <Button Background="Orange" Foreground="White" FontSize="20" Cursor="Hand">按钮2</Button> <Button Background="Orange" Foreground="White" FontSize="20" Cursor="Hand">按钮3</Button> <Button Background="Orange" Foreground="White" FontSize="20" Cursor="Hand">按钮4</Button> </StackPanel>
三、WrapPanel(*)
类似于充数的,随着页面的大小位置而改变
<WrapPanel> <Button Height="100" Width="100" Background="Orange" Foreground="White" FontSize="20" Cursor="Hand" Margin="10">按钮1</Button> <Button Height="100" Width="100" Background="Orange" Foreground="White" FontSize="20" Cursor="Hand" Margin="10">按钮2</Button> <Button Height="100" Width="100" Background="Orange" Foreground="White" FontSize="20" Cursor="Hand" Margin="10">按钮3</Button> <Button Height="100" Width="100" Background="Orange" Foreground="White" FontSize="20" Cursor="Hand" Margin="10">按钮4</Button> </WrapPanel>
四、DockPanel(*)
停靠栏,上下左右,中间
<DockPanel> <Button DockPanel.Dock="top" Background="Orange" Foreground="White" FontSize="20" Cursor="Hand" >按钮1</Button> <Button Background="Orange" Foreground="White" FontSize="20" Cursor="Hand" >按钮2</Button> <Button DockPanel.Dock="Bottom" Background="Orange" Foreground="White" FontSize="20" Cursor="Hand" >按钮3</Button> <Button DockPanel.Dock="Right" Background="Orange" Foreground="White" FontSize="20" Cursor="Hand" >按钮4</Button> <Button DockPanel.Dock="Top" Background="Orange" Foreground="White" FontSize="20" Cursor="Hand" >按钮5</Button> </DockPanel>
这篇关于WPF几种常用布局方式的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-19永别了,微服务架构!
- 2024-05-15鸿蒙生态设备数量超8亿台
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了
- 2024-05-09Google Chrome驱动程序 124.0.6367.62(正式版本)去哪下载?
- 2024-05-09有没有大佬知道这种数据应该怎么抓取呀?