名称 描述
StackPanel 在水平或垂直的堆栈中放置元素,通常应用于一个复杂的布局中的一小块区域
WrapPanel 在一系列可换行(列)的行中放置元素,支持水平、垂直方向,一行(列)放不下自动拍到下一行(列)
DockPanel 根据容器整个边界调整元素,指定上、下、左、右
Grid 网格布局,指定行列,经常使用
UniformGrid 在一个不可见但是强制所有单元格具有相同尺寸的网格中放置元素,不经常用
Canvas 使用固定坐标绝对定位,不太常用

所有这些布局容器都继承于System.Windows.Controls.Panel

1、StackPanel

名称 描述
Orientation(Horizontal、Vertical) 布局方向:水平与垂直
HorizontalAlignment、VerticalAlignment 水平方向:Center、Left、Right、Stretch
垂直方向:Center、Top、Bottom、Stretch
该属性决定元素在容器中靠左还是靠右还是居中
Margin="5,5,5,5" 容器周围的控件,左、上、右、下
MinWidth与MinHeight 设置最小宽度与高度
MaxWidth与MaxHeight 设置最大宽度与高度              
[html] view plaincopy
  1. <StackPanel Orientation="Vertical"  VerticalAlignment="Center" Margin="5,5,5,5" MinHeight="50" MinWidth="100" MaxWidth="600" MaxHeight="300" Height="200" Width="400">
  2. <Button Content="Hello World1" MinWidth="50" MaxWidth="100"></Button>
  3. <Button Content="Hello World2" MinWidth="50" MaxWidth="100"></Button>
  4. <Button Content="Hello World3" MinWidth="50" MaxWidth="100"></Button>
  5. <Button Content="Hello World4" MinWidth="50" MaxWidth="100"></Button>
  6. <Button Content="Hello World5" MinWidth="50" MaxWidth="100"></Button>
  7. <Button Content="Hello World6" MinWidth="50" MaxWidth="100"></Button>
  8. </StackPanel>

2、WrapPanel

[html] view plaincopy
  1. <WrapPanel Orientation="Horizontal"  VerticalAlignment="Center" Margin="5,5,5,5" MinHeight="50" MinWidth="100" MaxWidth="600" MaxHeight="300" Height="200" Width="400">
  2. <Button Content="Hello World1" MinWidth="50" MaxWidth="100"></Button>
  3. <Button Content="Hello World2" MinWidth="50" MaxWidth="100"></Button>
  4. <Button Content="Hello World3" MinWidth="50" MaxWidth="100"></Button>
  5. <Button Content="Hello World4" MinWidth="50" MaxWidth="100"></Button>
  6. <Button Content="Hello World5" MinWidth="50" MaxWidth="100"></Button>
  7. <Button Content="Hello World6" MinWidth="50" MaxWidth="100"></Button>
  8. </WrapPanel>

指定水平、垂直方向

3、DockPanel

[html] view plaincopy
  1. <DockPanel>
  2. <Menu DockPanel.Dock="Top">
  3. <MenuItem Header="文件"></MenuItem>
  4. <MenuItem Header="编辑"></MenuItem>
  5. </Menu>
  6. <TextBox DockPanel.Dock="Bottom"></TextBox>
  7. </DockPanel>

指定上下左右

4、Grid

[html] view plaincopy
  1. <Grid ShowGridLines="True" MinHeight="200" MinWidth="400">
  2. <Grid.RowDefinitions>
  3. <RowDefinition Height="40"></RowDefinition>
  4. <RowDefinition></RowDefinition>
  5. <RowDefinition></RowDefinition>
  6. </Grid.RowDefinitions>
  7. <Grid.ColumnDefinitions>
  8. <ColumnDefinition Width="100"></ColumnDefinition>
  9. <ColumnDefinition></ColumnDefinition>
  10. <ColumnDefinition></ColumnDefinition>
  11. </Grid.ColumnDefinitions>
  12. <Button Content="第一行第一列"  Height="40" Width="100" Grid.Row="0" Grid.Column="0" MinHeight="40" MinWidth="100"></Button>
  13. <Button Content="第一行第二列(跨两列)"  Height="40" Width="150" Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2" MinHeight="40" MinWidth="150"></Button>
  14. </Grid>

5、UniformGrid

[html] view plaincopy
  1. <UniformGrid Rows="2" Columns="2">
  2. <Button Content="Hello(0,0)" Margin="10,10,10,10"></Button>
  3. <Button Content="Hello(0,1)" Margin="10,10,10,10"></Button>
  4. <Button Content="Hello(1,0)" Margin="10,10,10,10"></Button>
  5. <Button Content="Hello(1,1)" Margin="10,10,10,10"></Button>
  6. </UniformGrid>

每一个网格大小一样

6、Canvas

[html] view plaincopy
  1. <Canvas>
  2. <Button Canvas.Left="10" Canvas.Top="10" Content="(10,10)"></Button>
  3. <Button Canvas.Left="30" Canvas.Top="30" Content="(30,30)"></Button>
  4. <Button Canvas.Left="100" Canvas.Top="60" Content="(100,60)"></Button>
  5. </Canvas>

WPF-常用布局容器相关推荐

  1. WPF 10天修炼 第四天- WPF布局容器

    WPF布局 WPF的窗口也就是Window类,是一个内容控件,该控件派生自ContentControl.内容控件有一个Content属性,该属性有一个限制,只能放置一个用户界面元素,或一个字符串.为了 ...

  2. C# WPF:初识布局容器

    StackPanel堆叠布局 StackPanel是简单布局方式之一,可以很方便的进行纵向布局和横向布局 StackPanel默认是纵向布局的 <Window x:Class="Wpf ...

  3. 【转】WPF之路-常用布局控件一

    WPF布局原则 不应显式设置大小 为了布局的稳定性,控件的大小应该可以自动适应容器.如下为新建一个窗体,默认包含一个Grid容器,该控件没有显式设置宽高,所以,在改变窗体大小的时候,该容器的大小也随着 ...

  4. 学习WPF——WPF布局——了解布局容器

    WPF布局工作内部原理 WPF渲染布局时主要执行了两个工作:测量和排列 测量阶段,容器遍历所有子元素,并询问子元素所期望的尺寸 排列阶段,容器在合适的位置放置子元素,并设置元素的最终尺寸 这是一个递归 ...

  5. 【基于WPF+OneNote+Oracle的中文图片识别系统阶段总结】之篇一:WPF常用知识以及本项目设计总结...

    篇一:WPF常用知识以及本项目设计总结:http://www.cnblogs.com/baiboy/p/wpf.html 篇二:基于OneNote难点突破和批量识别:http://www.cnblog ...

  6. 【基于WPF+OneNote+Oracle的中文图片识别系统阶段总结】之篇一:WPF常用知识以及本项目设计总结

    篇一:WPF常用知识以及本项目设计总结:http://www.cnblogs.com/baiboy/p/wpf.html 篇二:基于OneNote难点突破和批量识别:http://www.cnblog ...

  7. Extjs4 常用布局总结

    1.anchor 固定布局 子组件尺寸相对于容器的尺寸,即父容器容器的大小发生变化时,使用anchor布局的组件会根据规定的规则重新渲染位置和大小( width:500,height:300, ).一 ...

  8. WPF代码模板-布局部分

    Grid 两行和三列 <Grid ShowGridLines="True"> <Grid.RowDefinitions> <RowDefinition ...

  9. ElementUI Container布局容器

    ElementUI介绍 常用组件 container布局容器

最新文章

  1. GNU C和ANSI C的区别
  2. Python StringIO实现内存缓冲区中读写数据
  3. 一个基于SAP Hybris Commerce和微信的社交电商原型介绍
  4. Android之React Native平台与Android本地模块之间的调用
  5. 为了兴趣爱好,我该选嵌入式么?
  6. you *might* want to use the less safe log_bin_trust_function_creators variable
  7. 网络编程之 application/x-www-form-urlencoded MIME编码
  8. REST测试工具之curl(URL多参数)
  9. 游戏内存读取工具_不因内存弃旧爱,东芝Canvio Gaming移动硬盘评测
  10. 纽微特纪事:改个字串,竟然成了“二期工作”,还拖了几个月
  11. 翻翻git之---实用工具类Lazy(绝对的好东西,走过路过别错过)
  12. 新浪博客服务器是不是在维护,新浪博客是不是又在升级了?
  13. 正弦电压有效值推导过程(为什么与频率无关)
  14. MasterCard信用卡测试卡号-creditcard-1
  15. N皇后问题(c语言实现)
  16. 树莓派外接显示器黑屏_解决树莓派连接显示屏No Signal的问题
  17. 鸿蒙系统功能,华为HarmonyOS2.0系统功能都有哪些呢-华为鸿蒙系统HarmonyOS2.0功能介绍[图文]_咖绿茵手游站...
  18. docker(十)—— Windows系统下安装docker
  19. 荒野今天维护服务器吗,荒野行动1月29日为什么无法登录原因 今天停服更新维护吗?...
  20. 网络类型之BMA与NBMA的区别

热门文章

  1. 【Android 逆向】使用 DB Browser 查看并修改 SQLite 数据库 ( 从 Android 应用数据目录中拷贝数据库文件 | 使用 DB Browser 工具查看数据块文件 )
  2. 【EventBus】EventBus 源码解析 ( 注册订阅者总结 | EventBus 注册订阅者流程梳理 )
  3. 我的 Serverless 实战 — 云函数与触发器的创建与使用 ( 开通腾讯云 “ 云开发 “ 服务 | 创建云函数 | 创建触发器 | 测试触发器 )
  4. 【C++ 语言】引用 ( 引用简介 | 指针常量 | 常量指针 | 常引用 | 引用参数 | 引用 指针 对比 )
  5. 路由器发展编年史 完结篇
  6. Beta阶段——第4篇 Scrum 冲刺博客
  7. C#文件夹权限操作工具类
  8. Python文件处理
  9. 自定义 checkbox 新玩法 ?
  10. 为什么大多Virtual Globe程序纵向旋转效率比较低