wpf之WrapPanel

前言

WrapPanel类似winform中的FlowLayoutPanel,采用流式布局。

1、Orientation

该属性指定WrapPanel中子空间布局的方向,有水平和垂直方向两种

1)Horizontal 水平方向

子元素Button按照水平方向排列,如果一行排满了自动换下一行

csharp 复制代码
<Window x:Class="wpf之Canvas.MainWindow"
        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:wpf之Canvas"
        mc:Ignorable="d"
        Title="MainWindow" Height="200" Width ="200">

    <WrapPanel Orientation="Horizontal"    >
        <Button Width=" 50" Height=" 50" Content=" 1" />
        <Button Width=" 50" Height=" 50" Content=" 2" />
        <Button Width=" 50" Height=" 50" Content=" 3" />
        <Button Width=" 50" Height=" 50" Content=" 4" />
        <Button Width=" 50" Height=" 50" Content=" 5" />
    </WrapPanel >
</Window>

1)Vertical 垂直方向

子元素Button按照垂直方向排列,如果一列排满了自动换下一列

csharp 复制代码
<Window x:Class="wpf之Canvas.MainWindow"
        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:wpf之Canvas"
        mc:Ignorable="d"
        Title="MainWindow" Height="200" Width ="200">

    <WrapPanel Orientation="Vertical"     >
        <Button Width=" 50" Height=" 50" Content=" 1" />
        <Button Width=" 50" Height=" 50" Content=" 2" />
        <Button Width=" 50" Height=" 50" Content=" 3" />
        <Button Width=" 50" Height=" 50" Content=" 4" />
        <Button Width=" 50" Height=" 50" Content=" 5" />
    </WrapPanel >
</Window>

马工撰写的年入30万+C#上位机项目实战必备教程(点击下方链接即可访问文章目录)

1、《C#串口通信从入门到精通》

2、《C#与PLC通信从入门到精通 》

3、《C# Modbus通信从入门到精通》

4、《C#Socket通信从入门到精通 》

5、《C# MES通信从入门到精通》

6、《winform控件从入门到精通》

7、《C#操作MySql数据库从入门到精通》

相关推荐
ifeng09181 天前
HarmonyOS实战项目:AI健康助手(影像识别与健康分析)
人工智能·华为·wpf·harmonyos
Aevget1 天前
界面控件Telerik UI for WPF 2025 Q3亮点 - 集成AI编码助手
人工智能·ui·wpf·界面控件·ui开发·telerik
张人玉1 天前
WPF 数据绑定与转换器详解
c#·wpf·light
主宰者1 天前
WPF CalcBinding简化判断逻辑
c#·.net·wpf
Aevget1 天前
DevExpress WPF中文教程:Data Grid - 如何使用虚拟源?(五)
wpf·界面控件·devexpress·ui开发·.net 10
就是有点傻1 天前
使用PaddleOCRSharp大模型精选文字识别
c#
LeonDL1681 天前
【通用视觉框架】基于C#+Winform+OpencvSharp开发的视觉框架软件,全套源码,开箱即用
人工智能·c#·winform·opencvsharp·机器视觉软件框架·通用视觉框架·机器视觉框架
数据的世界011 天前
技术变革:为何C#与.NET是未来的开发方向
java·c#·.net
大龄Python青年1 天前
C#快入教程:Linux安装.NET
linux·c#·.net
我是唐青枫2 天前
C#.NET Random 深入解析:随机数生成原理与最佳实践
c#·.net