WPF布局之Grid

Grid属于网格布局,可以设置行列、宽度、高度、还有跨行显示

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*"/>
            <RowDefinition Height="1*"/>
            <RowDefinition Height="1*"/>
            <RowDefinition Height="1*"/>
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="1*"/>
            <ColumnDefinition Width="1*"/>
        </Grid.ColumnDefinitions>

        <!--将控件按照行列位置,自行安排显示区域-->
        <Border Grid.Row="0" Grid.Column="1" Background="Red"/>
        <Border Grid.Row="0" Grid.Column="0" Background="blue"/>
        <Border Grid.Row="1" Grid.Column="0" Background="Green"/>
        <Border Grid.Row="1" Grid.Column="1" Background="Black"/>

        <!--元素能够跨行跨列-->
        <Border Grid.Row="2" Grid.Column="0"  Grid.ColumnSpan="2" Background="Yellow"/>
        <Border Grid.Row="3" Grid.Column="0"  Grid.RowSpan="2" Background="Gold"/>

    </Grid>
</Window>
相关推荐
心平气和量大福大11 小时前
C#-WPF-Window主窗体
开发语言·c#·wpf
FuckPatience16 小时前
Telerik UI for WPF 值不能为null。参数名:key
ui·wpf
lindexi1 天前
WPF 笔迹延迟优化从硬件到软件的全链路分析
wpf
weixin_727535622 天前
双Token认证体系深度拆解:Spring Security + JWT + Redis
redis·spring·wpf
liuxiaowei32 天前
Winform+WPF双框架实战:喷涂工艺SCADA上位机从0到1搭建(附采集监控源码+车间踩坑实录)
大数据·hadoop·wpf
贺国亚3 天前
模型训练-分布式与GPU调度
分布式·wpf
不羁的木木3 天前
HarmonyOS技术精讲-Connectivity Kit:实战——多屏协同与文件快传应用
华为·wpf·harmonyos
某不知名網友4 天前
C++ 从零实现负载均衡式在线 OJ 判题系统|分布式沙箱判题实战
wpf
fogota4 天前
【AI】C# .NET8 WPF 第三方DLL引用配置(编译不丢失、不自动删除)
c#·.net·wpf·dll
不羁的木木4 天前
HarmonyOS技术精讲-Connectivity Kit(短距通信服务):初识统一短距通信框架
华为·wpf·harmonyos