Visual.VisualChildrenCount Property


获取 Visual 的子元素数量。Gets the number of child elements for the Visual.

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

Property Value


子元素的数量。The number of child elements.


下面的示例定义 VisualChildrenCount的重写实现。The following example defines an overridden implementation of VisualChildrenCount.

// Provide a required override for the VisualChildrenCount property.
protected override int VisualChildrenCount
    get { return _children.Count; }
' Provide a required override for the VisualChildrenCount property.
Protected Overrides ReadOnly Property VisualChildrenCount() As Integer
        Return _children.Count
    End Get
End Property


默认情况下,Visual 没有子级。By default, a Visual has no children. 因此,默认实现始终返回0。Therefore, the default implementation always returns 0.

Notes to Inheritors

派生自 Visual 的类必须重写此属性,并且还必须重写 GetVisualChild(Int32) 方法,以便正确枚举可视化树。A class that derives from Visual must override this property, and also the GetVisualChild(Int32) method, for the visual tree to be enumerated correctly.

Applies to