WPF笔记(1.4 布局)——Hello,WPF!
这一节只是第2章的引子。
布局要使用Panel控件,有四种Panel,如下:
DockPanel,就是设置停靠位置布局模型。
StackPanel,提供一个从左至右或从上至下放置内容的堆栈模型。
Grid,提供一个允许进行 行/网格定位的模型。可使用表格。
Canvas,可精确定位。
其中,Grid是最常用的,vs2005自动生成的Page和window都默认带有这个标签:
Example 1-25. A sample usage of the Grid panel
<Window
>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Button Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2">A</Button>
<Button Grid.Row="0" Grid.Column="2">C</Button>
<Button Grid.Row="1" Grid.Column="0" Grid.RowSpan="2">D</Button>
<Button Grid.Row="1" Grid.Column="1">E</Button>
<Button Grid.Row="1" Grid.Column="2">F</Button>
<Button Grid.Row="2" Grid.Column="1">H</Button>
<Button Grid.Row="2" Grid.Column="2">I</Button>
</Grid>
</Window>这段程序产生一个3x3表格。注意,先定义行格式,再定义列格式,最后是往单元格放入button。
Example 1-26. Arranging an image and text in a grid
<Button Width="100" Height="100">
<Button.Content>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Image Grid.Row="0" Source="tom.png" />
<TextBlock
Grid.Row="1"
HorizontalAlignment="Center">Tom</TextBlock>
</Grid>
</Button.Content>
</Button>这段程序是在图片下面加了一行Caption,也是用的Grid下表格排版。
以上两个例子都有Grid.Row=1这样的语法——attached-property牵连属性。即在Grid内部定义(),在外部控件Button中指定属性值。
牵连属性的用途,事先不一定用Button填充单元格,这样对所有控件就有任意性——暂时这么想,因为没看第二章。
WPF笔记(1.4 布局)——Hello,WPF!的更多相关文章
- WPF笔记1 用VS2015创建WPF程序
使用WPF创建第一个应用程序.实现功能如下: 单击"Red"按钮,文本显示红色:单击"Black"按钮,文本显示黑色:单击"Back"按钮, ...
- WPF笔记(2.8 常用的布局属性)——Layout
原文:WPF笔记(2.8 常用的布局属性)--Layout 这一节老没意思,啰里啰唆的尽是些HTML的属性,挑几个好玩的List出来,备忘:Padding与Margin的区别:Margin指控件边界与 ...
- WPF笔记(2.7 文字布局)——Layout
原文:WPF笔记(2.7 文字布局)--Layout 这一节介绍的是文字布局的几个控件:1.TextBlock 最基本的文字控件可以配置5个Font属性.TextWraping属性,&quo ...
- WPF笔记(2.9和2.10)——Layout
原文:WPF笔记(2.9和2.10)--Layout 2.9讲的是,如果内部设定超过容器大小,怎么办?StackPanel会裁剪越界部分DockPanel和Grid会智能判断,从而决定换行. 2.10 ...
- WPF笔记(2.5 Canvas)——Layout
原文:WPF笔记(2.5 Canvas)--Layout Canvas是最精确的布局容器--绝对定位,此书作者不建议使用,以为控件的大小一般会随着内部字体图片的动态生成而自动变化,所以使用前三种布局是 ...
- WPF笔记(2.2 DockPanel)——Layout
原文:WPF笔记(2.2 DockPanel)--Layout 读完了这一节,发现DockPanel就是过去winform中的Dock属性.原来的Dock属性是子控件设置,而其父亲级别不用设置.现在W ...
- WPF笔记(2.3 StackPanel)——Layout
原文:WPF笔记(2.3 StackPanel)--Layout StackPanel用于小规模的排版布局,比如说一个局部下几个textbox和Button啦.Orientation属性有Vertic ...
- WPF笔记一
笔记内容: BUG.WPF运行窗体时调用Hide()方法,然后再Show()异常的解决方案 WPF 窗体设置为无边框 选择本地文件 选择文件夹 WPF实现右下角弹出消息窗口 WPF 显示 HTTP 网 ...
- WPF笔记(2.6 ViewBox)——Layout
原文:WPF笔记(2.6 ViewBox)--Layout 在Canvas外面包一层ViewBox,可以使Canvas内的控件填充整个ViewBox,并随着ViewBox的大小变化而同步变化,这是因为 ...
随机推荐
- java获得指定日期的前一天,后一天的代码
/** * 获得指定日期的前一天 * @param specifiedDay * @return * @throws Exception */ public static String getSpec ...
- Android模仿微信语音聊天功能
项目效果如下: 项目目录结构如下: 代码如下: AudioManager.java import java.io.File; import java.io.IOException; import ja ...
- CentOS下安装无线网卡驱动 (转)
1. 确定自己的网卡和内核版本:lspci | grep Network #根据输出的信息确定网卡的型号.uname -a #确定内核版本 2. 配置yum使用RPMForg ...
- 01_docker学习总结
01 docker学习总结 toolbox https://hub.docker.com/ https://docs.docker.com/engine/installation/mac/#from- ...
- IOS Main函数
int main(int argc, char * argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSS ...
- base64转码
Base64是一种编码方法,可以将任意字符转成可打印字符.使用这种编码方法,主要不是为了加密,而是为了不出现特殊字符,简化程序的处理. JavaScript原生提供两个Base64相关方法. btoa ...
- codeforces 166C Median - from lanshui_Yang
C. Median time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...
- C++: int和string相互转换
假设在一个C++的程序中常常会用到int和string之间的互换.个人建议能够写成一个函数,下次用的时候直接调用就可以. #include <iostream> #include < ...
- 同一个页面多个CALayer重绘的办法
//知识点,CALayer的重绘,-(void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx 方法,CALayer的渐变色.多个CALa ...
- [SQL学习笔记][用exists代替全称量词 ]
学习sql的必经问题. 学生表student (id学号 Sname姓名 Sdept所在系) 课程表Course (crscode课程号 name课程名) 学生选课表transcript (studi ...