LYT-WPF-基础-布局-WrapPanel面板
已亲测!本文转自:WPF教程三:布局之WrapPanel面板 - .NET开发菜鸟 - 博客园 (cnblogs.com),感谢~~
WrapPanel:环绕面板
WrapPanel布局面板将各个控件从左至右按照行或列的顺序罗列,当长度或高度不够时就会自动调整进行换行,后续排序按照从上至下或从右至左的顺序进行。
Orientation——根据内容自动换行。当Orientation属性的值设置为 Horizontal:元素是从左向右排列的,然后自上至下自动换行。当Orientation属性的值设置为Vertical:元素是从上向下排列的,然后从左至右自动换行。
ItemHeight——所有子元素都一致的高度。每个子元素填充高度的方式取决于它的VerticalAlignment属性、Height属性等。任何比ItemHeight高的元素都将被截断。
ItemWidth——所有子元素都一致的宽度。每个子元素填充高度的方式取决于它的VerticalAlignment属性、Width属性等。任何比ItemWidth高的元素都将被截断。
1、Orientation属性的值设置为 Horizontal
示例效果图如下2图所示,图1是窗体宽度较小时候的效果,图2是窗体宽度拉大以后的效果
图1
图2
使用XAML代码实现:
<Window x:Class="WpfDemo.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="WrapPanel面板" Height="237" Width="525" WindowStartupLocation="CenterScreen"> <WrapPanel Orientation="Horizontal"> <Button Width="100">按钮1</Button> <Button Width="100">按钮2</Button> <Button Width="100">按钮3</Button> <Button Width="100">按钮4</Button> <Button Width="100">按钮5</Button> <Button Width="100">按钮6</Button> </WrapPanel> </Window>
2、Orientation属性的值设置为Vertical
示例效果图如下2图所示,图1是窗体高度较大时候的效果,图2是窗体高度较小时的效果
图1
图2
使用XAML代码实现:
<Window x:Class="WpfDemo.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="WrapPanel面板" Height="237" Width="525" WindowStartupLocation="CenterScreen"> <WrapPanel Orientation="Vertical"> <Button Width="100">按钮1</Button> <Button Width="100">按钮2</Button> <Button Width="100">按钮3</Button> <Button Width="100">按钮4</Button> <Button Width="100">按钮5</Button> <Button Width="100">按钮6</Button> </WrapPanel> </Window>
posted on 2023-05-31 11:13 Violin_Huang 阅读(39) 评论(0) 编辑 收藏 举报
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异