Visual.GetVisualChild(Int32) 方法

定義

傳回父 Visual 中所指定的 VisualCollection

C#
protected virtual System.Windows.Media.Visual GetVisualChild (int index);

參數

index
Int32

VisualCollection 中視覺物件的索引。

傳回

Visual

VisualCollection 中指定之 index 值處的子物件。

範例

下列範例會定義 覆寫的 實作 GetVisualChild

C#
// 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];
}

備註

根據預設,沒有 Visual 子系。 因此,預設實作一律會擲回 ArgumentOutOfRangeException

給繼承者的注意事項

衍生自 Visual 的類別必須覆寫這個方法,以及 VisualChildrenCount 屬性,才能正確列舉視覺化樹狀結構。

適用於

產品 版本
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7