FrameworkElement.VisualChildrenCount 属性

定义

获取此元素内可视子元素的数目。

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

属性值

Int32

此元素内可视子元素的数目。

示例

以下示例演示自定义装饰器如何使用它为其多个视觉子级维护的值声明 VisualCollection 的值,并通过重写 VisualChildrenCountGetVisualChild报告这些值。

// 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

注解

始终 FrameworkElement 返回零或一个实现 VisualChildrenCount 。 维护可能超过一个的视觉子集合的类必须同时覆盖此属性和 GetVisualChild

此属性通常用于确定当前子集合的上限,以便实现布局替代 (,MeasureOverrideArrangeOverride) 。

继承者说明

如果类支持子元素集合中的多个视觉子级,请重写此属性以返回该集合中的元素计数。 即使集合对象本身返回计数,也必须执行此操作。 WPF 框架级别的元素布局逻辑假定所有元素都将通过其 VisualChildrenCount 属性返回有效的计数。

适用于