Visual.GetVisualChild(Int32) 方法

定義

傳回父 Visual 中所指定的 VisualCollectionReturns the specified Visual in the parent VisualCollection.

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

參數

index
Int32

VisualCollection 中視覺物件的索引。The index of the visual object in the VisualCollection.

傳回

VisualCollection 中指定之 index 值處的子物件。The child in the VisualCollection at the specified index value.

範例

下列範例會定義 GetVisualChild的覆寫執行。The following example defines an overridden implementation of GetVisualChild.

// Provide a required override for the GetVisualChild method.
protected override Visual GetVisualChild(int index)
{
    if (index < 0 || index >= _children.Count)
    {
        throw new ArgumentOutOfRangeException();
    }

    return _children[index];
}
' Provide a required override for the GetVisualChild method.
Protected Overrides Function GetVisualChild(ByVal index As Integer) As Visual
    If index < 0 OrElse index >= _children.Count Then
        Throw New ArgumentOutOfRangeException()
    End If

    Return _children(index)
End Function

備註

根據預設,Visual 沒有任何子系。By default, a Visual has no children. 因此,預設的執行一律會擲回 ArgumentOutOfRangeExceptionTherefore, the default implementation always throws an ArgumentOutOfRangeException.

給繼承者的注意事項

衍生自 Visual 的類別必須覆寫這個方法,同時也是 VisualChildrenCount 屬性,才能正確列舉視覺化樹狀結構。A class that derives from Visual must override this method, and also the VisualChildrenCount property, for the visual tree to be enumerated correctly.

適用於