FrameworkElement.VisualChildrenCount 屬性

定義

取得這個項目內的視覺化子項目數。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 所宣告的值,並透過 VisualChildrenCountGetVisualChild的覆寫來報告這些值。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

備註

VisualChildrenCountFrameworkElement 實值一律會傳回零或一個。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.

這個屬性通常是用來判斷目前子集合的上限,以便執行版面配置覆寫(MeasureOverrideArrangeOverride)。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.

適用於