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数据库从入门到精通》

相关推荐
Dm_dotnet12 小时前
WPF应用绑定系统快捷键
c#
.NET修仙日记12 小时前
SQL Server实战指南:从基础CRUD到高并发处理的完整面试题库
面试·职场和发展·c#·.net·sql server·.net全栈经典面试题库
武文斌7714 小时前
项目学习总结:CAN总线、摄像头、STM32概述
linux·arm开发·stm32·单片机·嵌入式硬件·学习·c#
sali-tec14 小时前
C# 基于halcon的视觉工作流-章46-不匀面划痕
人工智能·算法·计算机视觉·c#
数字化顾问15 小时前
从 DAG 到 Shuffle:掌握 Spark RDD 宽窄依赖的调优密码
c#·linq
Happy coder17 小时前
【avalonia教程】11字符串格式化、avalonia自带绑定值的转换
c#·avalonia
Panda__Panda1 天前
docker项目打包演示项目(数字排序服务)
运维·javascript·python·docker·容器·c#
weixin_456904271 天前
基于.NET Framework 4.0的串口通信
开发语言·c#·.net
Tiger_shl1 天前
C# 预处理指令 (# 指令) 详解
开发语言·c#
sali-tec1 天前
C# 基于halcon的视觉工作流-章45-网格面划痕
开发语言·算法·计算机视觉·c#