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它會維護其多個視覺子系,並報告這些值的覆寫透過VisualChildrenCountGetVisualChildThe 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

備註

FrameworkElement實作VisualChildrenCount一律會傳回零或一次。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.

適用於