【WPF】UIElement中的Measure和Arrange调用过程

Measure

UIElement.Measure】的参数时可用空间(Size对象),这个空间通常代表父控件留给子空间显示的可用空间。

		/// <summary>
        /// Updates DesiredSize of the UIElement. Must be called by parents from theor MeasureCore, to form recursive update.
        /// This is first pass of layout update.
        /// </summary>
        /// <remarks>
        /// Measure is called by parents on their children. Internally, Measure calls MeasureCore override on the same object,
        /// giving it opportunity to compute its DesiredSize.<para/>
        /// This method will return immediately if child is not Dirty, previously measured
        /// and availableSize is the same as cached. <para/>
        /// This method also resets the IsMeasureinvalid bit on the child.<para/>
        /// In case when "unbounded measure to content" is needed, parent can use availableSize
        /// as double.PositiveInfinity. Any returned size is OK in this case.
        /// </remarks>
        /// <param name="availableSize">Available size that parent can give to the child. May be infinity (when parent wants to
        /// measure to content). This is soft constraint. Child can return bigger size to indicate that it wants bigger space and hope
        /// that parent can throw in scrolling...</param>
        public void Measure(Size availableSize)

MeasureOverride

///<Summary>
///<param = "finnalSize">父级中应使用此元素排列自身及其子元素的最终区域</param>
///<return>实际使用的大小</reutnr>
///</Summary>
protected virtual System.Windows.Size ArrangeOverride (System.Windows.Size finalSize);

MeasureCore

接着UIElement内部的MeasureCore会被调用,该方法去决定调用MeasureOverride的大小参数。
具体过程如下:

  1. 判断大小属性值是否被显示设置。
  2. 如果是,直接使用设置的值,它总会保持设置的大小(如果超出了父控件的规划大小,WPF会根据IsClipToBounds属性来决定是否裁剪它)
  3. 如果不是,那么MeasureCore会根据可用大小当前控件的属性(比如Margin)来决定最终传入MeasureOverride的可用大小参数。
		/// <summary>
        /// Measurement override. Implement your size-to-content logic here.
        /// </summary>
        /// <remarks>
        /// MeasureCore is designed to be the main customizability point for size control of layout.
        
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值