共用方式為


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

屬性值

這個項目的視覺化子項目數。

範例

下列範例示範自訂裝飾項 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

備註

VisualChildrenCountFrameworkElement 作一律會傳回零或一。 維護可能超過一個視覺子集合的類別必須同時覆寫這個屬性和 GetVisualChild

此屬性通常用來判斷目前子集合的上限,以便實作版面配置覆寫 (、 MeasureOverrideArrangeOverride) 。

給繼承者的注意事項

如果您的類別支援子專案集合中的一個以上的視覺子系,請覆寫這個屬性以傳回該集合中的專案計數。 即使集合物件本身傳回計數,您也必須這麼做。 WPF 架構層級的專案配置邏輯假設所有元素都會透過其 VisualChildrenCount 屬性傳回有效的計數。

適用於