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>
相关推荐
一见已难忘2 小时前
基于 Harmony 6.0 应用的宠物寄养预约系统实现
wpf·宠物
fl1768313 小时前
基于C#WPF实现的内存加速球清理类似360加速球内存清理
开发语言·c#·wpf
李高钢3 小时前
【WPF】高级 UI 与性能优化实战:从卡顿到丝滑
ui·性能优化·wpf
Chris _data21 小时前
WPF 上位机开发学习笔记 - 第四天
笔记·学习·wpf
李高钢21 小时前
除了 IDE,C#/WPF 开发者每天离不开的 10 个工具
ide·c#·wpf
李高钢1 天前
用 JetBrains Rider 写 WPF 的 15 个高效技巧:从 VS 转过来也值得看
wpf
李高钢2 天前
【WPF】MVVM 与数据绑定实战:从原理到完整项目
wpf
李高钢2 天前
【WPF】从 Avalon 到 .NET 10:WPF 平台演进史与特性全览
.net·wpf
李高钢3 天前
WPF MVVM Light 入门:从零到Hello World
c#·wpf
李高钢3 天前
WPF MVVM Light(三):RelayCommand 命令与 Messenger 消息
前端·c#·wpf