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>
相关推荐
小北方城市网18 小时前
Spring Cloud Gateway 生产级实践:高可用架构、灰度发布与故障排查
spring boot·redis·分布式·缓存·架构·wpf
ujainu18 小时前
Flutter for OpenHarmonyOS 前置知识:Dart语言详解(下)
flutter·wpf·harmonyos
bugcome_com19 小时前
WPF 数据模板(DataTemplate):优雅实现数据与 UI 的解耦
ui·wpf
小北方城市网1 天前
Redis 分布式锁与缓存三大问题解决方案
spring boot·redis·分布式·后端·缓存·wpf·mybatis
Aevget2 天前
DevExpress WPF中文教程:Data Grid - 如何绑定到有限制的自定义服务(五)?
wpf
yangSnowy2 天前
Redis数据类型
数据库·redis·wpf
资深web全栈开发2 天前
分布式锁的陷阱:Redlock 真的安全吗?
分布式·安全·wpf
James.TCG2 天前
VM访问View(Interaction)
wpf
掘根2 天前
【jsonRpc】项目介绍
wpf
工业甲酰苯胺2 天前
C#中的多级缓存架构设计与实现深度解析
缓存·c#·wpf