WPF笔记(2.9和2.10)——Layout
2.9讲的是,如果内部设定超过容器大小,怎么办?
StackPanel会裁剪越界部分
DockPanel和Grid会智能判断,从而决定换行。
2.10 自定义布局容器
自定义容器要实现两个方法MeasureOverride和ArrangeOverride,并保证遍历其下的所有子控件,使他们都执行Measure和Arrange方法。
using System;
using System.Windows.Controls;
using System.Windows;

namespace CustomPanel
{
public class DiagonalPanel : Panel
{

protected override Size MeasureOverride( Size availableSize )
{
double totalWidth = 0;
double totalHeight = 0;

foreach( UIElement child in Children )
{
child.Measure( new Size( double.PositiveInfinity,
double.PositiveInfinity ) );
Size childSize = child.DesiredSize;
totalWidth += childSize.Width;
totalHeight += childSize.Height;
}
return new Size( totalWidth, totalHeight );
}

protected override Size ArrangeOverride( Size finalSize )
{
Point currentPosition = new Point( );

foreach( UIElement child in Children )
{
Rect childRect = new Rect( currentPosition, child.DesiredSize );
child.Arrange( childRect );
currentPosition.Offset( childRect.Width, childRect.Height );
}
return new Size( currentPosition.X, currentPosition.Y );
}
}
}WPF笔记(2.9和2.10)——Layout的更多相关文章
- WPF笔记(2.5 Canvas)——Layout
原文:WPF笔记(2.5 Canvas)--Layout Canvas是最精确的布局容器--绝对定位,此书作者不建议使用,以为控件的大小一般会随着内部字体图片的动态生成而自动变化,所以使用前三种布局是 ...
- 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.6 ViewBox)——Layout
原文:WPF笔记(2.6 ViewBox)--Layout 在Canvas外面包一层ViewBox,可以使Canvas内的控件填充整个ViewBox,并随着ViewBox的大小变化而同步变化,这是因为 ...
- WPF笔记(2.4 Grid)——Layout
原文:WPF笔记(2.4 Grid)--Layout 第一章已经简单介绍过这个容器,这一节详细介绍.Grid一般是用表格(Grid.Row 和Grid.Column )的,比StackPanel更细致 ...
- 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笔记(1.10 绘图)——Hello,WPF!
原文:WPF笔记(1.10 绘图)--Hello,WPF! 书中的代码语法过时了,改写为以下(测试通过): <Button> <Button.L ...
- WPF笔记(1.9 样式和控件模板)——Hello,WPF!
原文:WPF笔记(1.9 样式和控件模板)--Hello,WPF! 资源的另一个用途是样式设置: <Window > <Window.Resources> <St ...
随机推荐
- C#调用WebService服务(动态调用)
原文:C#调用WebService服务(动态调用) 1 创建WebService using System; using System.Web.Services; namespace WebServi ...
- Qt编程之在QGraphics scene中使用图片
http://stackoverflow.com/questions/5960074/qimage-in-a-qgraphics-scene http://stackoverflow.com/ques ...
- Ruby的语法糖
发现Ruby的语法糖好多,比如函数调用,参数列表可以写括号和不写括号.代码块可以用do end 或者 {}. 还有 if,unless后置.等等. 如果看Ruby代码看多了,你会发现,它很多地方的 ...
- 同行blog收集
姜楠:http://www.slyar.com/blog/ 赵劼:http://blog.zhaojie.me/ 研究者July:http://my.csdn.net/v_JULY_v 王卓群:htt ...
- ZOJ3765---Lights (Splay伸展树)
Lights Time Limit: 8 Seconds Memory Limit: 131072 KB Now you have N lights in a line. Don't wor ...
- hdu 5396 Expression(区间dp)
Problem Description Teacher Mai has n numbers a1,a2,⋯,anand n−1 operators("+", "-&quo ...
- (转)A drop-in universal solution for moving text fields out of the way of the keyboard
There are a hundred and one proposed solutions out there for how to move UITextField andUITextView o ...
- Ubuntu 10.04下安装Opengl glx
1.安装OpenGL Library sudo apt-get install build-essential 2. 安装OpenGL Utilities sudo apt-get install l ...
- docke 网络配置2
一,docker 的bridge模式是和vmware中的nat模式类似的,但是如果想要弄成和vmwae中的bridge怎么办呢? 说明,bridge模式获取的Ip是与宿主机的ip是出于同一个网段的. ...
- Gson 简易笔记
#Gson 简易笔记 之前用 fastjson.它连个规矩的文档都没有,而且在github的wiki上写着: gson的g可能是"龟"拼音的缩写,龟速的json库." 各 ...