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

相关推荐
咕白m6251 小时前
通过 C# 复制 Excel 工作表
c#·.net
Humbunklung2 小时前
C# 获取docx文档页数的古怪方法
开发语言·microsoft·c#
苦荞米3 小时前
C#的MVVM架构中的几种数据绑定方式
wpf
软件黑马王子13 小时前
C#练习题——泛型实现单例模式和增删改查
开发语言·单例模式·c#
wangyue413 小时前
Doxygen with C#
c#
爱吃小胖橘13 小时前
Unity-动画基础
unity·c#·游戏引擎
arbboter14 小时前
【代码】关于C#支持文件和文本框的简单日志实现
数据库·c#·日志·log·日志库
Eiceblue15 小时前
使用 C# 操作 Excel 工作表:添加、删除、复制、移动、重命名
服务器·开发语言·c#·excel
娶不到胡一菲的汪大东15 小时前
C#第五讲 函数的用法
开发语言·c#
coding-fun16 小时前
SuperScript:C#脚本编辑器、C#脚本引擎
开发语言·c#·编辑器