FrameworkElement.GetVisualChild(Int32) 메서드

정의

GetVisualChild(Int32)를 재정의하며, 자식 요소 컬렉션에서 지정된 인덱스의 자식을 반환합니다.

protected:
 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

매개 변수

index
Int32

컬렉션에서 요청된 자식 요소의 인덱스(0부터 시작)입니다.

반환

Visual

요청된 자식 요소입니다. null을 반환하면 안 됩니다. 지정된 인덱스가 범위를 벗어난 경우 예외가 발생합니다.

예제

다음 예제에서는 사용자 지정 표시기가 여러 시각적 자식에 대해 유지 관리하는 값으로 VisualCollection 선언된 값을 사용하는 방법을 보여 줍니다. 이러한 값은 재정의 VisualChildrenCount 를 통해 보고됩니다 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 유효한 인덱스는 0뿐입니다. 콘텐츠 모델은 GetVisualChild 컬렉션이 아닌 0개 또는 1개의 자식 요소를 지원합니다.

상속자 참고

이 구현은 시각적 자식 요소의 더 이상 설명이 포함된 컬렉션을 유지하지 않는 요소에만 유효합니다. 이러한 컬렉션이 있는 모든 요소는 이 메서드를 재정의하고 해당 요소에서 지원하는 자식 요소 컬렉션의 동일한 인덱스로 인덱스 매핑해야 합니다. 범위의 인덱스(0 VisualChildrenCount 에서 빼기 1)는 유효한 요소를 반환해야 합니다. 다른 인덱스도 범위를 벗어난 예외를 throw해야 합니다. 자식 컬렉션을 지원하고 가능한 자식이 두 개 이상 반환되도록 재정 GetVisualChild(Int32) 의하는 요소 형식의 예는 다음과 같습니다 Panel.

기본 구현의 FrameworkElement 시각적 자식은 하나만 가정합니다. 0 이외의 값으로 index 전달되면 예외가 throw됩니다. 데코레이터, 표시기 또는 특수 렌더링이 있는 요소와 같은 몇 가지 일반적인 요소는 구현을 재정 FrameworkElement 의합니다(중간 기본 클래스의 구현). 일부 구현은 여전히 하나의 시각적 자식 개체를 적용하는 반면 다른 구현은 컬렉션을 허용합니다.

적용 대상