FrameworkElement.VisualChildrenCount FrameworkElement.VisualChildrenCount FrameworkElement.VisualChildrenCount FrameworkElement.VisualChildrenCount Property

定义

获取此元素内可视子元素的数目。Gets the number of visual child elements within this element.

protected:
 virtual property int VisualChildrenCount { int get(); };
protected override int VisualChildrenCount { get; }
member this.VisualChildrenCount : int
Protected Overrides ReadOnly Property VisualChildrenCount As Integer

属性值

此元素内可视子元素的数目。The number of visual child elements for this element.

示例

下面的示例演示自定义装饰器如何使用其为多个VisualCollection视觉对象维护的的值, 并通过重写和GetVisualChildVisualChildrenCount报告这些值。The following example shows how a custom adorner uses the values declared by a VisualCollection that it maintains for its multiple visual children and reports these values through overrides of VisualChildrenCount and GetVisualChild.

// To store and manage the adorner's visual children.
VisualCollection visualChildren;
' To store and manage the adorner's visual children.
Private visualChildren As VisualCollection
// Override the VisualChildrenCount and GetVisualChild properties to interface with 
// the adorner's visual collection.
protected override int VisualChildrenCount { get { return visualChildren.Count; } }
protected override Visual GetVisualChild(int index) { return visualChildren[index]; }
' Override the VisualChildrenCount and GetVisualChild properties to interface with 
' the adorner's visual collection.
Protected Overrides ReadOnly Property VisualChildrenCount() As Integer
	Get
		Return visualChildren.Count
	End Get
End Property
Protected Overrides Function GetVisualChild(ByVal index As Integer) As Visual
	Return visualChildren(index)
End Function

注解

FrameworkElementVisualChildrenCount实现始终返回零个或一个。The FrameworkElement implementation of VisualChildrenCount always returns either zero or one. 维护可能超过一个的视觉对象集合的类必须重写此属性和GetVisualChildClasses that maintain a visual child collection that might exceed one must override both this property and GetVisualChild.

此属性通常用于出于实现布局重写 (MeasureOverride, ArrangeOverride) 的目的确定当前子集合的上限。This property is generally used to determine the upper bounds of the current child collection for purposes of implementing the layout overrides (MeasureOverride, ArrangeOverride).

继承者说明

如果你的类支持子元素集合中的多个视觉对象, 请重写此属性以返回该集合中的元素计数。If your class supports more than one visual child in a child element collection, override this property to return the count of elements in that collection. 即使集合对象本身返回计数, 也必须执行此操作。You must do this even if the collection object itself returns a count. WPF 框架级别的元素布局逻辑假定所有元素都将通过其VisualChildrenCount属性返回有效计数。Element layout logic at the WPF framework level presumes that all elements will return a valid count through their VisualChildrenCount property.

适用于