WPF 布局控件 Grid表格

介绍

Grid表格布局控件,在WPF项目的界面布局中非常常用。主要是以行列进行元素控制的。

常用的属性

Grid.Row: 指定子元素所在的行。

Grid.Column: 指定子元素所在的列。

Grid.RowSpan 跨几行

Grid.ColumnSpan 跨几列

RowSpacing: 设置或获取行之间的空间。

ColumnSpacing: 设置或获取列之间的空间。

Margin: 设置或获取网格的外边距。

Padding: 设置或获取网格的内边距。

定义行数 2 行

<Grid.RowDefinitions>

<RowDefinition/>

<RowDefinition/>

</Grid.RowDefinitions>

定义列数 2列

<Grid.ColumnDefinitions>

<ColumnDefinition/>

<ColumnDefinition/>

</Grid.ColumnDefinitions>

示例代码

复制代码
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition Height="45"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition Width="220"/>
    </Grid.ColumnDefinitions>
    <!--Grid.ColumnSpan 跨2列-->
    <vm:VmRenderControl Grid.Row="0" Grid.Column="0" 
                Grid.ColumnSpan="2" x:Name="vrcRender" />

    <!--Grid.Row="1" Grid.Column="0" 将按钮放在第二行第一列的单元格中-->
    <Button Grid.Row="1" Grid.Column="0" x:Name="btnGetResult" Click="btnGetResult_Click" 
    Content="获取方案结果" Width="200" Height="35" HorizontalAlignment="Left"/>
    <!--Grid.Row="1" Grid.Column="1" 将按钮放在第二行第二列的单元格中-->
    <Button Grid.Row="1" Grid.Column="1" Name="btnRun" Click="btnRun_Click" 
    Content="运行" Width="200" Height="35" HorizontalAlignment="Left"/>
</Grid>
相关推荐
Scout-leaf11 小时前
WPF新手村教程(三)—— 路由事件
c#·wpf
西岸行者2 天前
学习笔记:SKILLS 能帮助更好的vibe coding
笔记·学习
starlaky2 天前
Django入门笔记
笔记·django
勇气要爆发2 天前
吴恩达《LangChain LLM 应用开发精读笔记》1-Introduction_介绍
笔记·langchain·吴恩达
悠哉悠哉愿意2 天前
【单片机学习笔记】串口、超声波、NE555的同时使用
笔记·单片机·学习
勇气要爆发2 天前
吴恩达《LangChain LLM 应用开发精读笔记》2-Models, Prompts and Parsers 模型、提示和解析器
android·笔记·langchain
qianshanxue112 天前
计算机操作的一些笔记标题
笔记
土拨鼠烧电路2 天前
笔记11:数据中台:不是数据仓库,是业务能力复用的引擎
数据仓库·笔记
土拨鼠烧电路2 天前
笔记14:集成与架构:连接孤岛,构建敏捷响应能力
笔记·架构
烟花落o2 天前
栈和队列的知识点及代码
开发语言·数据结构·笔记·栈和队列·编程学习