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>
相关推荐
bugcome_com7 小时前
WPF 核心布局控件全解析:从 Grid 到 UniformGrid 的实战应用
c#·wpf
观无8 小时前
WPF-Datagrid控件的无缝滚动
wpf
꧁༺℘₨风、凌๓༻꧂10 小时前
C# WPF 项目中集成 Pdf查看器
pdf·c#·wpf
Kiyra1 天前
WebSocket vs HTTP:为什么 IM 系统选择长连接?
分布式·websocket·网络协议·http·设计模式·系统架构·wpf
要记得喝水1 天前
某公司C#-WPF面试题-来自nowcoder(含答案和解析)--2
c#·wpf
Joker 0071 天前
Linux nohup命令实战指南
linux·运维·wpf
时光追逐者1 天前
一个 WPF 开源、免费的 SVG 图像查看控件
开源·c#·.net·wpf
de之梦-御风1 天前
【WebAPI 模拟器】.NET 8/9 + Minimal API + Swagger + DI + WPF Host
.net·wpf·web
Zhen (Evan) Wang1 天前
WPF基于MVVM实现自定义分页控件
wpf
柒.梧.1 天前
MyBatis一对多嵌套查询实战:SQL99式与分布式查询双视角解析
wpf