WPF布局之WrapPanel

WrapPanel一般用于修饰部分空间的元素排布,默认水平排布,可通过属性Orientation,修改排列方式,这种布局能够自动换行适应排布,放下所有控件,不像StackPanel排布,放不下了会被遮盖住

cs 复制代码
<Window x:Class="Wpf_LayoutGrid.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_LayoutGrid"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <!--设置行列数量和宽度高度,高度可以设置成比例、绝对值和auto自适应-->
        <Grid.RowDefinitions>
            <RowDefinition Height="1*"/>
            <RowDefinition Height="1*"/>
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="1*"/>
            <ColumnDefinition Width="1*"/>
        </Grid.ColumnDefinitions>
         <!--默认垂直排序,通过属性Orientation修改排列方式,放不下了就被遮挡住了-->
        <StackPanel Orientation="Horizontal">
            <Button Width="100" Height="40"/>
            <Button Width="100" Height="40"/>
            <Button Width="100" Height="40"/>
            <Button Width="100" Height="40"/>
            <Button Width="100" Height="40"/>
            <Button Width="100" Height="40"/>
        </StackPanel>
        
        <!--默认水平排序,通过属性Orientation修改排列方式,放不下了会自动换行-->
        <WrapPanel Grid.Row="1">
            <Button Width="100" Height="40"/>
            <Button Width="100" Height="40"/>
            <Button Width="100" Height="40"/>
            <Button Width="100" Height="40"/>
            <Button Width="100" Height="40"/>
            <Button Width="100" Height="40"/>
        </WrapPanel>

    </Grid>
</Window>
相关推荐
Macbethad3 小时前
WPF工业设备工艺配方流程程序技术方案
wpf
清风徐来Groot3 小时前
WPF布局之UniformGrid
wpf
清风徐来Groot3 小时前
WPF布局之StackPanel
wpf
500841 天前
鸿蒙 Flutter 权限管理进阶:动态权限、权限组、兼容处理与用户引导
flutter·华为·架构·wpf·开源鸿蒙
500841 天前
鸿蒙 Flutter 蓝牙与 IoT 开发进阶:BLE 设备连接、数据交互与设备管理
flutter·华为·electron·wpf·开源鸿蒙
Macbethad1 天前
工业设备系统管理程序技术方案
大数据·wpf
500841 天前
鸿蒙 Flutter 混合栈开发:与 React Native/ArkTS 页面无缝集成(2025 爆火方案)
flutter·华为·electron·wpf·开源鸿蒙
拾七片晚星2 天前
MateChat工作流引擎实战:复杂任务自动化编排与异常处理
wpf·devui·matechat
Aevget2 天前
界面控件开发包DevExpress v25.1.7更新上线——修复一些小bug
c#·wpf·winform·devexpress·ui开发·用户界面