前言
WrapPanel類似winform中的FlowLayoutPanel,采用流式布局。
1、Orientation
該屬性指定WrapPanel中子空間布局的方向,有水平和垂直方向兩種
1)Horizontal 水平方向
子元素Button按照水平方向排列,如果一行排滿了自動換下一行
<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按照垂直方向排列,如果一列排滿了自動換下一列
<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數據庫從入門到精通》