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 练手项目的更多相关文章

  1. Python学习路径及练手项目合集

    Python学习路径及练手项目合集 https://zhuanlan.zhihu.com/p/23561159

  2. web前端学习部落22群分享给需要前端练手项目

    前端学习还是很有趣的,可以较快的上手然后自己开发一些好玩的项目来练手,网上也可以一抓一大把关于前端开发的小项目,可是还是有新手在学习的时候不知道可以做什么,以及怎么做,因此,就整理了一些前端项目教程, ...

  3. webpack练手项目之easySlide(三):commonChunks(转)

    Hello,大家好. 在之前两篇文章中: webpack练手项目之easySlide(一):初探webpack webpack练手项目之easySlide(二):代码分割 与大家分享了webpack的 ...

  4. webpack练手项目之easySlide(二):代码分割(转)

    在上一篇 webpack练手项目之easySlide(一):初探webpack  中我们一起为大家介绍了webpack的基本用法,使用webpack对前端代码进行模块化打包. 但是乍一看webpack ...

  5. Python之路【第二十四篇】:Python学习路径及练手项目合集

      Python学习路径及练手项目合集 Wayne Shi· 2 个月前 参照:https://zhuanlan.zhihu.com/p/23561159 更多文章欢迎关注专栏:学习编程. 本系列Py ...

  6. 练手项目:利用pygame库编写射击游戏

    本项目使用pygame模块编写了射击游戏,目的在于训练自己的Python基本功.了解中小型程序框架以及学习代码重构等.游戏具有一定的可玩性,感兴趣的可以试一下. 项目说明:出自<Python编程 ...

  7. Vue练手项目(包含typescript版本)

    本项目的git仓库https://github.com/lznism/xiachufang-vue 对应的使用typescript实现的版本地址https://github.com/lznism/xi ...

  8. 适合Python的5大练手项目, 你练了么?

    在练手项目的选择上,还存在疑问?不知道要从哪种项目先下手? 首先有两点建议: 最好不要写太应用的程序练手,要思考什么更像是知识,老只会写写爬虫是无用的,但是完全不写也不行. 对于练手的程序,要注意简化 ...

  9. 适合Python 新手的5大练手项目,你练了么?

    接下来就给大家介绍几种适合新手的练手项目. 0.算法系列-排序与查找 Python写swap很方便,就一句话(a, b = b, a),于是写基于比较的排序能短小精悍.刚上手一门新语言练算法最合适不过 ...

随机推荐

  1. Axure学习(一)

    了解Axure目前的一些评价信息以及可以学习Axure的网址.

  2. spring cloud Feign 使用 @RequestLine 注解遇到的问题

    package com.itmuch.cloud; import org.springframework.cloud.netflix.feign.FeignClient; import com.itm ...

  3. java 泛型: 通配符? 和 指定类型 T

    1. T通常用于类后面和 方法修饰符(返回值前面)后面 ,所以在使用之前必须确定类型,即新建实例时要制定具体类型, 而?通配符通常用于变量 ,在使用时给定即可 ? extends A  :  通配符上 ...

  4. 获取JavaScript异步函数的返回值

    今天研究一个小问题: 怎么拿到JavaScript异步函数的返回值? 1.错误尝试 当年未入行时,我的最初尝试: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <s ...

  5. SpringBoot获取resource下证书失败

    1.第一种失败的情况:    本来使用Spring的上下文容器获取文件,将证书文件放在resource下,编译后获取文件会出现报错 java.security.spec.InvalidKeySpecE ...

  6. 复制粘贴容易犯的错误 eclipse

    有时候复制原有的代码到xml文件中,会提示某文件没有找到,一般该文件名字改成别的了,这时候为了解决这问题一般需要对这个文件重命名

  7. java struts2 的 文件下载

    jsp: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEnco ...

  8. CRC在线计算工具

    http://www.lammertbies.nl/comm/info/crc-calculation.html

  9. linux_开启mysql服务

    想要连接mysql的时候必须先开启mysql的服务 service mysqld start mysql -u root -p 输入密码

  10. 697. Degree of an Array

    static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...