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>
相关推荐
烟话62 天前
MVVM核心机制:属性通知与命令绑定解析
wpf
不知名君2 天前
WPF 的原生窗体标题栏主题自适应系统深浅主题
wpf
碎碎念的安静2 天前
WPF 与 Qt 进程间通信(IPC)
开发语言·qt·wpf
军训猫猫头3 天前
7.带输入参数的线程启动 C# + WPF 完整示例
开发语言·前端·c#·.net·wpf
周杰伦fans4 天前
WPF Prism 框架完全入门指南:从环境搭建到弹窗导航实战
wpf
雨浓YN4 天前
WPF MVVM 模式(无调库)项目创建笔记
笔记·wpf
周杰伦fans4 天前
.NET AOT技术深度解析:为什么WPF不支持而Avalonia/UWP支持?
.net·wpf
雨浓YN4 天前
WPF MVVM 模式(调Prism库)项目创建笔记 —— 包含C++/CLI OpenCV互操作
c++·笔记·wpf
七夜zippoe4 天前
DolphinDB数据模型:表、分区与分布式表
分布式·wpf·数据模型··dolphindb
一念春风5 天前
Qwen2.5 (AI模型 PC搭建)
人工智能·ai·c#·wpf·模型