FrameworkContentElement.Parent 속성

정의

논리적 트리에서 이 요소의 부모를 가져옵니다.

public:
 property System::Windows::DependencyObject ^ Parent { System::Windows::DependencyObject ^ get(); };
public System.Windows.DependencyObject Parent { get; }
member this.Parent : System.Windows.DependencyObject
Public ReadOnly Property Parent As DependencyObject

속성 값

DependencyObject

이 요소의 논리적 부모입니다.

예제

다음 예제에서는 해당 형식이 Parent TextPointer 특정 형식인지 여부를 확인합니다.

// Traverse content in forward direction until the position is immediately after the opening 
// tag of a Run element, or the end of content is encountered.
while (position != null)
{
    // Is the current position just after an opening element tag?
    if (position.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementStart)
    {
        // If so, is the tag a Run?
        if (position.Parent is Run)
            break;
    }

    // Not what we're looking for; on to the next position.
    position = position.GetNextContextPosition(LogicalDirection.Forward);
}
' Traverse content in forward direction until the position is immediately after the opening 
' tag of a Run element, or the end of content is encountered.
Do While position IsNot Nothing
    ' Is the current position just after an opening element tag?
    If position.GetPointerContext(LogicalDirection.Backward) = TextPointerContext.ElementStart Then
        ' If so, is the tag a Run?
        If TypeOf position.Parent Is Run Then
            Exit Do
        End If
    End If

    ' Not what we're looking for on to the next position.
    position = position.GetNextContextPosition(LogicalDirection.Forward)
Loop

설명

요소의 논리적 부모 애플리케이션 기능에 따라 변경 될 수 있습니다 하 고이 속성의 값을 유지 하면 해당 변경 내용이 반영 되지 note 합니다. 일반적으로 필요하기 직전에 값을 가져와야 합니다.

논리 트리를 트래버스하는 방법에 대한 자세한 내용은 WPF의 트리 를 참조하고 요소 검색에 대해 이 방법을 사용하는 것이 적절한 시나리오를 참조하세요.

일부 속성은 논리 트리를 통해 값을 상속하기 때문에 속성 시스템이 다시 분리될 때 요소의 모든 속성 값을 다시 계산할 수 있습니다. 바인딩에 적용되는 항목은 DataContext 요소가 다시 매개 변수가 될 때 변경될 수도 있습니다.

요소의 부모 변경은 일반적으로 컬렉션 조작, 전용 추가 또는 제거 메서드 사용 또는 요소의 콘텐츠 속성 설정을 통해서만 수행됩니다.

속성을 사용하는 Parent 가장 일반적인 시나리오는 참조를 가져온 다음 부모로부터 다양한 FrameworkContentElement 속성 값을 가져오는 것입니다. 템플릿의 경우 템플릿은 Parent 결국 null입니다. 이 지점을 지나 템플릿이 실제로 적용되는 논리 트리로 확장하려면 다음을 사용합니다 TemplatedParent.

적용 대상

추가 정보