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

相关推荐
为自己_带盐2 小时前
在 Blazor Server 中集成 docx-preview.js 实现高保真 Word 预览
javascript·c#·word
hixiong1232 小时前
C# OpenvinoSharp部署DDDDOCR验证码识别模型
opencv·c#·ocr·openvino
唐青枫3 小时前
C#.NET ConcurrentBag<T> 设计原理与使用场景
c#·.net
玩泥巴的12 小时前
飞书 .NET SDK 事件处理的幂等性与去重机制
c#·.net·二次开发·飞书
在路上看风景12 小时前
3.2 FileStream
c#
zwm26988881512 小时前
6号楼 部分声光24v电压达不到,显示11v
c#
椒颜皮皮虾16 小时前
TensorRtSharp:在 C# 世界中释放 GPU 推理的极致性能
c#·tensorrt
行止9516 小时前
WinForms 彻底隐藏 滚动条的终极解决方案
c#
bugcome_com17 小时前
WPF样式进阶实战:外置样式+MVVM主题切换+样式优先级全解析
c#·.net·wpf