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>
相关推荐
上海物联网1 天前
Prism WPF中的自定义区域适配器解决了什么问题?在项目中怎么实现一个自定义适配器
wpf
code bean1 天前
【C#高级】TCP请求-应答模式的WPF应用实战
tcp/ip·c#·wpf
极客智造1 天前
WPF 实现可复用晶圆 n*n 网格自定义控件(支持选中与圆形裁剪)
wpf
上海物联网2 天前
Prism Regions-自定义区域适配器实现开发者将任意 WPF 控件转换为可动态加载视图的区域容器
面试·wpf
Aevget3 天前
DevExpress WPF中文教程:Data Grid - 如何绑定到有限制的自定义服务(四)?
wpf·界面控件·devexpress·ui开发·.net 10
棉晗榜3 天前
wpf DataGrid控制列是否显示,DataGrid列不会触发Visibility的转换器
wpf
超级种码3 天前
Redis:Redis高可用——副本、哨兵和集群
数据库·redis·wpf
棉晗榜3 天前
wpf给Border添加闪烁边框
wpf
Derrick_itRose3 天前
DevExpress笔记WPF(2)Data Editors and Controls(基础编辑器)
笔记·编辑器·wpf
He BianGu3 天前
【笔记】WPF的Binding中AsyncState的使用方式
笔记·wpf