WPF布局控件之WrapPanel

article/2025/10/25 7:05:39

WrapPanel

WrapPanel,英文意思是折叠容器,那到底是怎么个折叠法呢?如下:

在这里插入图片描述

<Window x:Class="LearnLayout.WrapPanelWin"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:local="clr-namespace:LearnLayout"mc:Ignorable="d"Title="WrapPanelWin" Height="450" Width="800"><WrapPanel><Button Content="牛马人的一生" Background="lavender"/><Button Content="我不是牛马" Background="Pink"/><Button Content="下辈子还当牛马" Background="Snow"/><Button Content="牛马人的一生" Background="lavender"/><Button Content="我不是牛马" Background="Pink"/><Button Content="下辈子还当牛马" Background="Snow"/><Button Content="牛马人的一生" Background="lavender"/><Button Content="我不是牛马" Background="Pink"/><Button Content="下辈子还当牛马" Background="Snow"/><Button Content="牛马人的一生" Background="lavender"/><Button Content="我不是牛马" Background="Pink"/><Button Content="下辈子还当牛马" Background="Snow"/></WrapPanel>
</Window>

相当于是WPF会根据WrapPanel中的控件一个接一个排列在WrapPanel中,如果宽度(或高度)不够,那么就会自己换行。这就解释了为什么叫折叠容器。那这里只能看到宽度对布局的影响,为什么说高度呢?和StackPanel一样,可以根据Orientation属性来设置其水平或垂直布局方向,如下:

在这里插入图片描述

<Window x:Class="LearnLayout.WrapPanelWin"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:local="clr-namespace:LearnLayout"mc:Ignorable="d"Title="WrapPanelWin" Height="450" Width="800"><WrapPanel Orientation="Vertical"><Button Content="牛马人的一生" Background="lavender"/><Button Content="我不是牛马" Background="Pink"/><Button Content="下辈子还当牛马" Background="Snow"/><Button Content="牛马人的一生" Background="lavender"/><Button Content="我不是牛马" Background="Pink"/><Button Content="下辈子还当牛马" Background="Snow"/><Button Content="牛马人的一生" Background="lavender"/><Button Content="我不是牛马" Background="Pink"/><Button Content="下辈子还当牛马" Background="Snow"/><Button Content="牛马人的一生" Background="lavender"/><Button Content="我不是牛马" Background="Pink"/><Button Content="下辈子还当牛马" Background="Snow"/><Button Content="牛马人的一生" Background="lavender"/><Button Content="我不是牛马" Background="Pink"/><Button Content="下辈子还当牛马" Background="Snow"/><Button Content="牛马人的一生" Background="lavender"/><Button Content="我不是牛马" Background="Pink"/><Button Content="下辈子还当牛马" Background="Snow"/><Button Content="牛马人的一生" Background="lavender"/><Button Content="我不是牛马" Background="Pink"/><Button Content="下辈子还当牛马" Background="Snow"/><Button Content="牛马人的一生" Background="lavender"/><Button Content="我不是牛马" Background="Pink"/><Button Content="下辈子还当牛马" Background="Snow"/></WrapPanel>
</Window>

StackPanel不一样的是,WrapPanel默认是水平的(Orientation="Horizontal"),而StackPanel默认是垂直的(Orientation="Vertical")。
那如果WrapPanel中各控件的宽(或者高)不一样呢?如果是水平布局下,那么当前行的高度受其当前行中控件宽度最高的控件控制,反之,垂直布局中,当前列的宽度受其当前列控件宽度最宽的控件控制,如下:

水平:
在这里插入图片描述

<Window x:Class="LearnLayout.WrapPanelWin"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:local="clr-namespace:LearnLayout"mc:Ignorable="d"Title="WrapPanelWin" Height="450" Width="800"><WrapPanel Orientation="Horizontal"><Button Content="牛马人的一生" Background="lavender" Height="200"/><Button Content="我不是牛马" Background="Pink"/><Button Content="下辈子还当牛马" Background="Snow"/><Button Content="牛马人的一生" Background="lavender"/><Button Content="我不是牛马" Background="Pink"/><Button Content="下辈子还当牛马" Background="Snow"/><Button Content="牛马人的一生" Background="lavender"/><Button Content="我不是牛马" Background="Pink"/><Button Content="下辈子还当牛马" Background="Snow"/><Button Content="牛马人的一生" Background="lavender"/><Button Content="我不是牛马" Background="Pink"/><Button Content="下辈子还当牛马" Background="Snow"/><Button Content="牛马人的一生" Background="lavender"/><Button Content="我不是牛马" Background="Pink"/><Button Content="下辈子还当牛马" Background="Snow"/><Button Content="牛马人的一生" Background="lavender"/><Button Content="我不是牛马" Background="Pink"/><Button Content="下辈子还当牛马" Background="Snow"/><Button Content="牛马人的一生" Background="lavender"/><Button Content="我不是牛马" Background="Pink"/><Button Content="下辈子还当牛马" Background="Snow"/><Button Content="牛马人的一生" Background="lavender"/><Button Content="我不是牛马" Background="Pink"/><Button Content="下辈子还当牛马" Background="Snow"/></WrapPanel>
</Window>

垂直:
在这里插入图片描述

<Window x:Class="LearnLayout.WrapPanelWin"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:local="clr-namespace:LearnLayout"mc:Ignorable="d"Title="WrapPanelWin" Height="450" Width="800"><WrapPanel Orientation="Vertical"><Button Content="牛马人的一生" Background="lavender" Width="200"/><Button Content="我不是牛马" Background="Pink"/><Button Content="下辈子还当牛马" Background="Snow"/><Button Content="牛马人的一生" Background="lavender"/><Button Content="我不是牛马" Background="Pink"/><Button Content="下辈子还当牛马" Background="Snow"/><Button Content="牛马人的一生" Background="lavender"/><Button Content="我不是牛马" Background="Pink"/><Button Content="下辈子还当牛马" Background="Snow"/><Button Content="牛马人的一生" Background="lavender"/><Button Content="我不是牛马" Background="Pink"/><Button Content="下辈子还当牛马" Background="Snow"/><Button Content="牛马人的一生" Background="lavender"/><Button Content="我不是牛马" Background="Pink"/><Button Content="下辈子还当牛马" Background="Snow"/><Button Content="牛马人的一生" Background="lavender"/><Button Content="我不是牛马" Background="Pink"/><Button Content="下辈子还当牛马" Background="Snow"/><Button Content="牛马人的一生" Background="lavender"/><Button Content="我不是牛马" Background="Pink"/><Button Content="下辈子还当牛马" Background="Snow"/><Button Content="牛马人的一生" Background="lavender"/><Button Content="我不是牛马" Background="Pink"/><Button Content="下辈子还当牛马" Background="Snow"/></WrapPanel>
</Window>

http://chatgpt.dhexx.cn/article/QPBB3f5V.shtml

相关文章

.NET WPF教程(7)——布局介绍WrapPanel与StackPanel(②)

三. WrapPanel WrapPanel布局面板将各个控件从左至右按照行或列的顺序罗列&#xff0c;当长度或高度不够是就会自动调整进行换行&#xff0c;后续排序按照从上至下或从右至左的顺序进行。 Orientation——根据内容自动换行。当 Horizontal选项看上去类似于Windows资源管理器…

WPF 用代码实现WrapPanel右侧自动对齐(解决多余空白问题)

未处理前效果&#xff1a; 处理后效果&#xff1a; <Border Background"{StaticResource BorderBg}" BorderThickness"2" BorderBrush"{StaticResource BorderBrush}" CornerRadius"5" Padding"5" x:Name"SvK…

C# Grid StackPanel DockPanel WrapPanel

WPF面板布局介绍Grid、StackPanel、DockPanel、WrapPanel 回顾 上一篇&#xff0c;我们介绍了基本控件及控件的重要属性和用法&#xff0c;我们本篇详细介绍WPF中的几种布局容器及每种布局容器的使用场景&#xff0c;当 然这些都是本人在实际项目中的使用经验&#xff0c;可能…

WPF基础五:UI①布局元素WrapPanel

目录 WrapPanel WrapPanel类 XAML范例&#xff1a; C#代码 WrapPanel 按从左到右的顺序位置定位子元素&#xff0c;在包含框的边缘处将内容切换到下一行。 后续排序按照从上至下或从右至左的顺序进行&#xff0c;具体取决于 Orientation 属性的值。 WrapPanel包含UIElemen…

一个优化奇怪的 WrapPanel

一个优化奇怪的 WrapPanel 本文经原作者授权以原创方式二次分享&#xff0c;欢迎转载、分享。 一个优化奇怪的 WrapPanel 作者&#xff1a;陈-林-赵-魏 原文链接[1]&#xff1a;https://www.cnblogs.com/wandia/p/17092221.html FixToRB 附加属性&#xff0c;固定到【右边(水平…

WPF布局之WrapPanel与StackPanel

转载&#xff1a;https://www.cnblogs.com/Im-Victor/p/10565030.html 三. WrapPanel WrapPanel布局面板将各个控件从左至右按照行或列的顺序罗列&#xff0c;当长度或高度不够是就会自动调整进行换行&#xff0c;后续排序按照从上至下或从右至左的顺序进行。 Orientation——…

WrapPanel在不同页面渲染使用

WrapPanel渲染的使用 WrapPanel在UserControl用户控件的使用 页面控件的是渲染出来&#xff0c;在UserControl用户控件的使用无法直接使用&#xff0c;使用会出现空&#xff0c;没法渲染获取到WrapPanel控件。 没法渲染获取效果图&#xff1a; 想成功获取渲染获取到WrapPane…

WPF 入门教程WrapPanel介绍

WrapPanel将定位每个子控件的旁边&#xff0c;另外&#xff0c;水平方向&#xff08;默认值&#xff09;或垂直&#xff0c;直到没有更多的空间&#xff0c;在那里将换到下一行&#xff0c;然后继续。当您想要一个垂直或水平列表控件在没有更多空间时自动换行时使用它。 当 Wr…

WPF WrapPanel、UniformGrid、DockPanel介绍

WPF WrapPanel、UniformGrid、DockPanel介绍 WrapPanel WrapPanel , 具有在有限的容器范围内, 可以自动换行, 或者换列处理。具体则取决于WrapPanel的排列方式 (Orientation)。 Orientation"Horizontal"时各控件从左至右罗列&#xff0c;当面板长度不够时&#xff…

WPF控件之WrapPanel的用法

简单来说&#xff0c;WrapPanel就是一个可以行填充&#xff0c;自动换行。或者列填充&#xff0c;自动换列的一个布局容器。 如下所示&#xff0c;它会自动将10个button分成2行 <WrapPanel><Button Content"button1" /><Button Content"button…

WrapPanel:自动折行面板(环绕面板)基础简述

WrapPanel布局面板将各个控件从左至右按照行或列的顺序罗列&#xff0c;当长度或高度不够时就会自动调整进行换行或换列&#xff0c;后续排序按照从上至下或从右至左的顺序进行。 Orientation——根据内容自动换行。当Orientation属性的值设置为 Horizontal&#xff1a;元素是…

WPF 控件专题 WrapPanel 控件详解

1、WrapPanel 介绍 官方释义&#xff1a;WrapPanel&#xff08;环绕面板&#xff09;&#xff1a;按从左到右的顺序位置定位子元素&#xff0c;在包含框的边缘处将内容切换到下一行。 后续排序按照从上至下或从右至左的顺序进行&#xff0c;具体取决于 Orientation 属性的值。 …

UI Automation编程辅助工具Inspect的下载和使用

UIAutomation微软提供的UI自动化库&#xff0c;主要用AutomationElement类来表示UI 自动化目录树中的一个UI自动化元素&#xff0c;.NET Windows的窗体应用程序和WPF应用程序。 Inspect是一款类似于SPY的界面捕捉工具。外观如下&#xff1a; 下载地址&#xff1a; Inspect.zip …

docker inspect --format 详解

docker inspect --format 文章目录 docker inspect --format1. 什么是模板2. Go模板语法3. 变量3.1 系统变量 {{.}}3.2 自定义变量3.3 遍历&#xff08;循环&#xff09;&#xff1a;range 4. index5. 判断5.1 not5.2 or5.3 判断条件5.4 判断示例 6. 打印信息9. 管道10. 内置函…

android studio inspect code,Android Studio使用inspect code删除 unused import

项目经常需要从别的项目复制一些文件过来&#xff0c;但是经常出现大片的导包unused import&#xff0c;但是我用自动导包并没有效果&#xff0c;必须把这些错误的导包手动删除才可以导入正确的包&#xff0c;虽然文件不多&#xff0c;手动删除是可以完成的&#xff0c;但是作为…

Halcon Variable Inspect 安装失败

这里写自定义目录标题 Halcon Variable Inspect 安装失败 Halcon Variable Inspect 安装失败 在 Visual Studio 2022 环境下安装 HALCON2105ProgressVariableInspect.vsix 失败。 点击 “View Install Log” 查看日志。 主要问题在运行vsix文件时&#xff0c;它会监控然后运行…

docker inspect 查看部分数据

1. 问题描述 使用docker inspect命令可查看 docker 镜像/容器/数据卷 等的具体配置docker inspect命令格式docker inspect [参数] 容器名/容器ID/镜像名/镜像ID/数据卷名...如果不加参数&#xff0c;则输出很多&#xff0c;难以精确查看真正关心的内容 如果使用grep 表达式&am…

【网络教程】如何安装inspect.exe

文章目录 安装 安装 Inspect&#xff08;Inspect.exe&#xff09;是一个基于Windows的工具&#xff0c;允许您选择任何UI元素并查看元素的可访问性数据。您可以查看Microsoft UI自动化属性和控制模式&#xff0c;以及Microsoft活动辅助功能属性。Inspect还允许您测试UI自动化树…

inspect.exe安装使用

官网下载 https://developer.microsoft.com/zh-cn/windows/downloads/windows-sdk/ 官网教程 https://learn.microsoft.com/zh-cn/windows/win32/winauto/inspect-objects 要求 系统要求 Windows SDK 具有以下最低系统要求&#xff1a; 支持的操作系统 Windows 10版本 150…

python中inspect模块用法详解

获取函数签名对象。函数签名包含了一个函数的信息&#xff0c;包括函数名、它的参数类型、它所在的类和名称空间及其他信息&#xff09;。 inspect模块主要提供了四种用处&#xff1a; 对是否是模块、框架、函数进行类型检查获取源码获取类或者函数的参数信息解析堆栈 1、对…