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>
相关推荐
He BianGu17 小时前
【笔记】在WPF中GiveFeedbackEventHandler的功能和应用场景详细介绍
笔记·wpf
就是有点傻17 小时前
WPF自定义控件-水晶球
wpf
He BianGu19 小时前
【笔记】在WPF中QueryContinueDragEvent的详细介绍
笔记·wpf
He BianGu19 小时前
【笔记】在WPF中QueryCursor事件的功能和应用场景详细介绍
笔记·wpf
He BianGu19 小时前
【笔记】在WPF中CommandManager的功能和应用场景详细介绍
笔记·wpf
关关长语20 小时前
HandyControl中Button图标展示多色路径
c#·.net·wpf·handycontrol
baivfhpwxf20232 天前
WPF DataGrid 指定列的数据可以编辑功能开发
wpf
求学中--3 天前
万物互联的钥匙:HarmonyOS SDK 深度解析与实战指南
wpf
武藤一雄3 天前
WPF Command 设计思想与实现剖析
windows·微软·c#·.net·wpf·.netcore
Aevget3 天前
DevExpress WPF中文教程:Data Grid - 服务器模式和即时反馈模式
.net·wpf·界面控件·devexpress·ui开发