首页 > 其他分享 >【自定义控件】MyPanelParent MyParent

【自定义控件】MyPanelParent MyParent

时间:2022-11-30 03:22:25浏览次数:25  
标签:控件 自定义 Windows System item new using MyParent Size

代码

MyPanelParent.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace MyPanels
{
    public class MyPanelParent : Panel
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="availableSize">1、UIElement Measure()方法 根据元素的Clip、Visibility生成constraintSize,然后传递给 FrameworkElement 的MeasureCore()方法  2、</param>
        /// <returns></returns>
        protected override  Size MeasureOverride(Size availableSize)
        {
            foreach (UIElement item in this.InternalChildren)
            {
                item.Measure(new Size(120, 120));//这里是入口
            }

            return availableSize;
        }

        protected override  Size ArrangeOverride(Size finalSize)
        {
            double x = 100;
            foreach (UIElement item in this.InternalChildren)
            {
                item.Arrange(new Rect(x, 0, item.DesiredSize.Width, item.DesiredSize.Height));
                x += item.DesiredSize.Width;
            }

            return finalSize;
        }
    }

}

MyPanel.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace MyPanels
{
    public class MyPanel : Panel
    {
        protected override System.Windows.Size MeasureOverride(System.Windows.Size availableSize)
        {
            foreach (UIElement item in this.InternalChildren)
            {
                item.Measure(availableSize);
            }
            return new Size(50, 50);//MyPanel 返回它期望的大小
        }

        protected override System.Windows.Size ArrangeOverride(System.Windows.Size finalSize)
        {
            double xCordinate = 0;
            foreach (UIElement item in this.InternalChildren)
            {
                item.Arrange(new Rect(new Point(xCordinate, 0), item.DesiredSize));
                xCordinate += item.DesiredSize.Width;
            }
            return finalSize;
        }
    }
}

效果

 

 

具体过程分析

 

标签:控件,自定义,Windows,System,item,new,using,MyParent,Size
From: https://www.cnblogs.com/cdaniu/p/16937284.html

相关文章

  • 判断闰年(自定义函数)
    #pragmawarning(disable:4996)#include<stdio.h>panduanrunnian(intn){if((n%4==0&&n%100!=0)||(n%400==0)){return1;}elsereturn0;}......
  • 自定义构造函数 创建对象
    函数适用于封装方法的  构造函数就是用于封装对象的1.构造函数首字母大写2.调用通过newnew函数名()3.通过this添加属性//functionPig(name,age){//......
  • 自定义数组的方法
    <body><script>//自己定义数组扩展方法求和和最大值//console.dir(Array);//console.log(Array.prototype);//Array.prototyp......
  • 自定义的Qt日期选择控件
    此控件也能作为日历控件使用。实现了Windows系统日历控件的鼠标悬停有白色渐变的效果(见于下图18日周围的白色渐变效果)。从中可以学习到Qt日期类的常用方法,和渐变画刷的使用......
  • .Net Core中自定义认证实现
    一、起因最近项目中需要对项目同时支持JWT认证,以及自定义的认证校验方式认证。通过对官方文档了解,得到认证实现主要通过继承 IAuthenticationHandler 或 Authenticat......
  • ArcObjects SDK开发 007 自定义App-Command-Tool框架
    1、为什么再设计一套App-Command-Tool框架为什么我们要自己再设计一套App-Command框架,而不直接使用AOAPI中的AxControl-ICommand这套已经非常好的框架呢?1、宿主不同。我......
  • WPF控件模板(6)
    什么是ControlTemplate?ControlTemplate(控件模板)不仅是用于来定义控件的外观、样式,还可通过控件模板的触发器(ControlTemplate.Triggers)修改控件的行为、响应动画等......
  • 汇编实验:自定义键盘中断的处理函数
    汇编实验报告-键盘中断1.实验任务:采用键盘中断方式,当输入是字符或数字的时候,回显输入并回车换行;否则退出。2.运行环境:Windows11+MASM3.题目分析:在课上我们刚刚学习......
  • android自定义view实现progressbar的效果
    一键清理是很多Launcher都会带有的功能,其效果也比较美观。实现方式也许有很多中,其中常见的是使用图片drawable来完成的,具体可以参考这篇文章:​​模仿......
  • c语言自定义输出小数点位数
    C语言中常用的小数有两种类型,分别是float或double;float称为单精度浮点型,double称为双精度浮点型。不像整数,小数没有那么多幺蛾子,小数的长度是固定的,float始终占用4个......