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>
相关推荐
清风徐来Groot2 小时前
WPF布局之WrapPanel
wpf
Macbethad3 小时前
WPF工业设备工艺配方流程程序技术方案
wpf
清风徐来Groot3 小时前
WPF布局之UniformGrid
wpf
清风徐来Groot3 小时前
WPF布局之StackPanel
wpf
500841 天前
鸿蒙 Flutter 权限管理进阶:动态权限、权限组、兼容处理与用户引导
flutter·华为·架构·wpf·开源鸿蒙
500841 天前
鸿蒙 Flutter 蓝牙与 IoT 开发进阶:BLE 设备连接、数据交互与设备管理
flutter·华为·electron·wpf·开源鸿蒙
Macbethad1 天前
工业设备系统管理程序技术方案
大数据·wpf
500841 天前
鸿蒙 Flutter 混合栈开发:与 React Native/ArkTS 页面无缝集成(2025 爆火方案)
flutter·华为·electron·wpf·开源鸿蒙
拾七片晚星2 天前
MateChat工作流引擎实战:复杂任务自动化编排与异常处理
wpf·devui·matechat