MeasureOverride和ArrangeOverride 练手项目
public class Diagnol:Panel
{
/// <summary>
/// 测量
/// </summary>
/// <param name="availableSize">This的尺寸</param>
/// <returns></returns>
protected override Size MeasureOverride(Size availableSize)
{
Size size = new Size();
foreach (UIElement item in this.InternalChildren)
{
item.Measure(availableSize);
size.Width += item.DesiredSize.Width;
size.Height += item.DesiredSize.Height;
}
//返回所有子控件需要的 总尺寸
return base.MeasureOverride(size);
} /// <summary>
/// 排列每个子控件
/// </summary>
/// <param name="finalSize">This的尺寸</param>
/// <returns></returns>
protected override Size ArrangeOverride(Size finalSize)
{
Point point1 = new Point();
//子控件个数
int count = this.InternalChildren.Count;
//总个数的中间值
int index = (count + ) / -;
for (int i = ; i < this.InternalChildren.Count; i++)
{
var child = this.InternalChildren[i];
//如果就一个没法玩,直接排列
if (count <= )
{
//设置子控件的位置
child.Arrange(new Rect(point1, child.DesiredSize));
break;
} //玩起来
if (i < index)
{
child.Arrange(new Rect(point1, child.DesiredSize));
point1.X += child.DesiredSize.Width;
point1.Y += child.DesiredSize.Height;
}
else
{
child.Arrange(new Rect(point1, child.DesiredSize));
point1.X += child.DesiredSize.Width;
point1.Y -= child.DesiredSize.Height;
}
}
return base.ArrangeOverride(finalSize);
}
}
<local:Diagnol>
<Button BorderBrush="Black" Background="Red" Content="0" Width="40"></Button>
<Button BorderBrush="Black" Background="Red" Content="1" Width="40"></Button> <Button BorderBrush="Black" Background="Red" Content="2" Width="40"></Button>
<Button BorderBrush="Black" Background="Red" Content="3" Width="40"></Button> <Button BorderBrush="Black" Background="Red" Content="4" Width="40"></Button> <Button BorderBrush="Black" Background="Red" Content="5" Width="40"></Button> <Button BorderBrush="Black" Background="Red" Content="6" Width="40"></Button>
<Button BorderBrush="Black" Background="Red" Content="7" Width="40"></Button> <Button BorderBrush="Black" Background="Red" Content="8" Width="40"></Button>
</local:Diagnol>
MeasureOverride和ArrangeOverride 练手项目的更多相关文章
- Python学习路径及练手项目合集
Python学习路径及练手项目合集 https://zhuanlan.zhihu.com/p/23561159
- web前端学习部落22群分享给需要前端练手项目
前端学习还是很有趣的,可以较快的上手然后自己开发一些好玩的项目来练手,网上也可以一抓一大把关于前端开发的小项目,可是还是有新手在学习的时候不知道可以做什么,以及怎么做,因此,就整理了一些前端项目教程, ...
- webpack练手项目之easySlide(三):commonChunks(转)
Hello,大家好. 在之前两篇文章中: webpack练手项目之easySlide(一):初探webpack webpack练手项目之easySlide(二):代码分割 与大家分享了webpack的 ...
- webpack练手项目之easySlide(二):代码分割(转)
在上一篇 webpack练手项目之easySlide(一):初探webpack 中我们一起为大家介绍了webpack的基本用法,使用webpack对前端代码进行模块化打包. 但是乍一看webpack ...
- Python之路【第二十四篇】:Python学习路径及练手项目合集
Python学习路径及练手项目合集 Wayne Shi· 2 个月前 参照:https://zhuanlan.zhihu.com/p/23561159 更多文章欢迎关注专栏:学习编程. 本系列Py ...
- 练手项目:利用pygame库编写射击游戏
本项目使用pygame模块编写了射击游戏,目的在于训练自己的Python基本功.了解中小型程序框架以及学习代码重构等.游戏具有一定的可玩性,感兴趣的可以试一下. 项目说明:出自<Python编程 ...
- Vue练手项目(包含typescript版本)
本项目的git仓库https://github.com/lznism/xiachufang-vue 对应的使用typescript实现的版本地址https://github.com/lznism/xi ...
- 适合Python的5大练手项目, 你练了么?
在练手项目的选择上,还存在疑问?不知道要从哪种项目先下手? 首先有两点建议: 最好不要写太应用的程序练手,要思考什么更像是知识,老只会写写爬虫是无用的,但是完全不写也不行. 对于练手的程序,要注意简化 ...
- 适合Python 新手的5大练手项目,你练了么?
接下来就给大家介绍几种适合新手的练手项目. 0.算法系列-排序与查找 Python写swap很方便,就一句话(a, b = b, a),于是写基于比较的排序能短小精悍.刚上手一门新语言练算法最合适不过 ...
随机推荐
- python正则表达式获取两段标记内的字符串
比如获取绿色字符串 ModelData.PayTableData =[{"}, {"}, {"}]; ModelData.PayTableData1 =[{"} ...
- Delegate,Action,Func,匿名方法,匿名委托,事件 (转载)
Delegate,Action,Func,匿名方法,匿名委托,事件 (转载) 一.委托Delegate 一般的方法(Method)中,我们的参数总是string,int,DateTime...这些基本 ...
- 提升HTML5的性能体验系列之五 webview启动速度优化及事件顺序解析
webview加载时有5个事件.触发顺序为loading.titleUpdate.rendering.rendered.loaded.webview开始载入页面时触发loading,载入过程中如果&l ...
- linux的!的用法
!的用法:1.!!:代表上一条命令,如下: 示例一: ./some-shell-command cat !! (相当于cat ./some-shell-command) 示例二: cd /user ! ...
- hibernate项目
http://blog.csdn.net/wzygis/article/details/22985751
- idea在哪执行maven clean?
- boost-智能指针
使用boost的智能指针需要包含头文件"boost/smart_ptr.hpp",c++11中需要包含头文件<memory> 1.auto_ptr.scoped_ptr ...
- Vim编辑器入门
vim(vimsual)是Linux/UNIX系列OS中通用的全屏编辑器. vim分为两种状态,即命令状态和编辑状态,在命令状态下,所键入的字符系统均作命令来处理,如:q代表退出,而编辑状态则是用来编 ...
- LPCSTR与CString转换
1.LPCSTR是Win32和VC++所使用的一种字符串数据类型,L表示long,P表示指针,C表示常量,STR表示字符串. 2.LPCSTR转化为CString: LPCSTR lpStr=&qu ...
- Office2013 如何安装Matlab notebook
Office2013 如何安装Matlab notebook 听语音 浏览:912 | 更新:2014-09-16 07:02 1 2 3 4 5 6 7 分步阅读 Office2013(64bit) ...