首页 > 代码库 > WPF (VisualChildren)可视化子元素详解

WPF (VisualChildren)可视化子元素详解

VisualChildrenCount    的 FrameworkElement 实现始终返回 0 或 1。  如果类所要维护的可视化子元素集合的成员数可能超过 1,则这样的类必须重写此属性和 GetVisualChild。 

此属性通常用于确定当前子元素集合的上限,以便实现布局重写(MeasureOverride、ArrangeOverride)。

 

 1 protected override Size MeasureOverride(Size constraint) 2         { 3             int visualChildrenCount = this.VisualChildrenCount; 4             if (visualChildrenCount > 0) 5             { 6                 UIElement uIElement = (UIElement)this.GetVisualChild(0); 7                 if (uIElement != null) 8                 { 9                     Helper.SetMeasureDataOnChild(this, uIElement, constraint);10                     uIElement.Measure(constraint);11                     return uIElement.DesiredSize;12                 }13             }14             return new Size(0.0, 0.0);15         }16         protected override Size ArrangeOverride(Size arrangeBounds)17         {18             int visualChildrenCount = this.VisualChildrenCount;19             if (visualChildrenCount > 0)20             {21                 UIElement uIElement = (UIElement)this.GetVisualChild(0);22                 if (uIElement != null)23                 {24                     uIElement.Arrange(new Rect(arrangeBounds));25                 }26             }27             return arrangeBounds;28         }

 

未完。。。。。。

WPF (VisualChildren)可视化子元素详解