WPF教程(三十一)Grid网格跨越
来源:互联网 发布:java用户登录注册代码 编辑:程序博客网 时间:2024/06/05 08:15
Grid默认每一个控件占据一个单元格,但是有些情况下你需要某个控件占据多行或者多列。在这种情况下,可以使用ColumnSpan和RowSpan这两个附加属性来实现。这两个属性默认的值都是1,也就是一个单元格,你可以指定大于1的数字来让控件跨越多行或者多列。
下面的例子使用了ColunmSpan属性:
<span style="font-size:14px;"><Window x:Class="WpfTutorialSamples.Panels.GridColRowSpan" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="GridColRowSpan" Height="110" Width="300"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="1*" /> <ColumnDefinition Width="1*" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <Button>Button 1</Button> <Button Grid.Column="1">Button 2</Button> <Button Grid.Row="1" Grid.ColumnSpan="2">Button 3</Button> </Grid></Window></span>
我们定义了两行两列,分配一样的空间。前两个按钮和正常使用一样,第三个按钮使用了ColumnSpan属性,使得它占据了第二行的两列。
上面的场景比较简单,因此联合几个面板也可以实现这个效果,但是在某些复杂的场景下,上面的功能就非常有用了。下面继续来看一个例子:
<span style="font-size:14px;"><Window x:Class="WpfTutorialSamples.Panels.GridColRowSpanAdvanced" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="GridColRowSpanAdvanced" Height="300" Width="300"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="*" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="*" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <Button Grid.ColumnSpan="2">Button 1</Button> <Button Grid.Column="3">Button 2</Button> <Button Grid.Row="1">Button 3</Button> <Button Grid.Column="1" Grid.Row="1" Grid.RowSpan="2" Grid.ColumnSpan="2">Button 4</Button> <Button Grid.Column="0" Grid.Row="2">Button 5</Button> </Grid></Window></span>
三行三列就能产生9个单元格,但是在这个例子中,我们将5个按钮填充到了对应的空间。一个控件可以跨越多行、多列、或者同时跨越多行多列,像按钮4一样。
总之,在Grid里跨越多行或者多列非常容易。在后面的文章中,我们将通过一个更加实用的例子,来演示使用其他Grid技术实现跨越。
0 0
- WPF教程(三十一)Grid网格跨越
- CSS网格布局(Grid)完全教程
- WPF教程(二十八)Grid
- WPF教程(三十)Grid单元格
- WPF之路——Grid(网格)
- WPF教程(二十九)Grid行和列
- WPF教程(三十二)使用Grid:一个联系人表格
- Grid View(网格视图)
- WPF Elements数据网格使用教程
- WPF Elements用户界面套包数据网格教程
- JBoss 系列三十一:JBoss Data Grid(Infinispan)缓存模式
- css grid布局教程之什么是网格布局?
- CSS Grid布局教程之网格单元格布局
- qml学习------------Grid(网格布局)
- Grid of WPF (一)
- WPF(Grid与布局)
- C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(三十一) 超酷万变的矢量魔法
- 网格计算Grid Computing
- Canvas 的绘制图表的基本用法
- mtk lcm调试
- 第九周—ASCII码排序
- 设计模式学习之旅--java篇
- Android软键盘遮挡布局的那些事
- WPF教程(三十一)Grid网格跨越
- Forward Selection
- 中国未来15年无人驾驶的发展路线
- 重装Source Insight 3.5出现问题
- linux 下安装anaconda,import的时候没有权限
- 一张图让你详细理解Group By的分组聚合过程
- liux下安装httpd过程
- 【Qt入门实践】Linux下Qt开发环境的搭建
- Eclipse的JavaWeb环境配置