FrameworkElement.GetVisualChild(Int32) FrameworkElement.GetVisualChild(Int32) FrameworkElement.GetVisualChild(Int32) FrameworkElement.GetVisualChild(Int32) Method


覆寫 GetVisualChild(Int32),並從子項目集合傳回指定索引處的子系。Overrides GetVisualChild(Int32), and returns a child at the specified index from a collection of child elements.

 override System::Windows::Media::Visual ^ GetVisualChild(int index);
protected override System.Windows.Media.Visual GetVisualChild (int index);
override this.GetVisualChild : int -> System.Windows.Media.Visual
Protected Overrides Function GetVisualChild (index As Integer) As Visual


Int32 Int32 Int32 Int32

集合中要求的子項目之以零為起始的索引。The zero-based index of the requested child element in the collection.


要求的子項目。The requested child element. 這應該不會傳回 null;如果提供的索引超出範圍,則會擲回例外狀況。This should not return null; if the provided index is out of range, an exception is thrown.


下列範例顯示自訂裝飾項如何使用它為其多個VisualCollection視覺子系維護的所宣告的值。The following example shows how a custom adorner uses the values declared by a VisualCollection that it maintains for its multiple visual children. 這些值是透過和VisualChildrenCount GetVisualChild的覆寫來報告。These values are reported 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
		Return visualChildren.Count
	End Get
End Property
Protected Overrides Function GetVisualChild(ByVal index As Integer) As Visual
	Return visualChildren(index)
End Function


FrameworkElement在執行中, 唯一有效的索引是零。In the FrameworkElement implementation, the only valid index is zero. 的內容模型GetVisualChild支援零或一個子專案, 而不是集合。The content model for GetVisualChild supports either zero or one child elements, not a collection.


這個實作用僅適用于不會維護任何更具描述性之視覺子專案集合的元素。This implementation is only valid for elements that do not maintain any more descriptive collection of visual child elements. 任何具有這類集合的元素都必須覆寫這個方法, 並將索引對應至該專案所支援之子專案集合中的對等索引。Any element that does have such a collection must override this method and map the index to an equivalent index in the child element collection that is supported by that element. 範圍從零到VisualChildrenCount (減一) 的索引應傳回有效的專案; 任何其他索引都應擲回超出範圍的例外狀況。An index in the range from zero to VisualChildrenCount (minus one) should return a valid element; any other index should throw an out-of-range exception. 支援子集合並覆寫GetVisualChild(Int32)以傳回多個可能子系之元素類型的範例為。 PanelAn example of an element type that does support a child collection and overrides GetVisualChild(Int32) to return more than one possible child is Panel.

FrameworkElement的預設實值只會假設一個視覺子系。The default implementation in FrameworkElement presumes only one visual child. 任何針對零傳遞index的值都會導致擲回例外狀況。Any value passed for index other than zero causes an exception to be thrown. 有數個常見的FrameworkElement元素, 例如裝飾專案、裝飾項或具有特定轉譯的元素, 會覆寫實作為 (從中繼基類執行)。Several common elements, such as decorators, adorners, or elements with specialized rendering, override the FrameworkElement implementation (of the implementation from intermediate base classes). 某些執行仍然會強制使用一個視覺子系, 而其他則允許集合。Some implementations still enforce one visual child whereas others allow a collection.