RelativeSource 클래스

정의

바인딩 대상의 위치를 기준으로 하여 바인딩 소스 위치를 설명하는 태그 확장을 구현합니다.

public ref class RelativeSource : System::Windows::Markup::MarkupExtension, System::ComponentModel::ISupportInitialize
[System.Windows.Markup.MarkupExtensionReturnType(typeof(System.Windows.Data.RelativeSource))]
public class RelativeSource : System.Windows.Markup.MarkupExtension, System.ComponentModel.ISupportInitialize
[<System.Windows.Markup.MarkupExtensionReturnType(typeof(System.Windows.Data.RelativeSource))>]
type RelativeSource = class
    inherit MarkupExtension
    interface ISupportInitialize
Public Class RelativeSource
Inherits MarkupExtension
Implements ISupportInitialize
상속
RelativeSource
특성
구현

예제

다음 예제에서는 만든 스타일 트리거는 ToolTip 유효성 검사 오류 메시지를 보고 하는 합니다. 사용 하 여는 RelativeSource 오류 내용의 현재 속성 setter의 값을 바인딩합니다 TextBox (의 TextBox 스타일을 사용 하 여). 이 예제에 대 한 자세한 내용은 참조 하세요. 방법: 바인딩 유효성 검사 구현합니다.

<Style x:Key="textBoxInError" TargetType="{x:Type TextBox}">
  <Style.Triggers>
    <Trigger Property="Validation.HasError" Value="true">
      <Setter Property="ToolTip"
        Value="{Binding RelativeSource={x:Static RelativeSource.Self},
                        Path=(Validation.Errors)/ErrorContent}"/>
    </Trigger>
  </Style.Triggers>
</Style>

다음 예제는 Style 사용자 지정 컨트롤의 정의 NumericUpDown합니다. Text 의 속성을 TextBlock 바인딩되는 Value 되는 개체의는 TemplatedParentNumericUpDown 이 제어 Style 이 경우에 적용 됩니다.

<!--ControlTemplate for NumericUpDown that inherits from
    Control.-->
<Style TargetType="{x:Type local:NumericUpDown}">
  <Setter Property="HorizontalAlignment" Value="Center"/>
  <Setter Property="VerticalAlignment" Value="Center"/>
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="{x:Type local:NumericUpDown}">
        <Grid Margin="3">
          <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
          </Grid.RowDefinitions>
          <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
          </Grid.ColumnDefinitions>

          <Border BorderThickness="1" BorderBrush="Gray" 
                  Margin="2" Grid.RowSpan="2" 
                  VerticalAlignment="Center" HorizontalAlignment="Stretch">
                  
            <TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Value}" 
                       Width="60" TextAlignment="Right" Padding="5"/>
          </Border>
          
          <RepeatButton Command="{x:Static local:NumericUpDown.IncreaseCommand}"  
                        Grid.Column="1" Grid.Row="0">Up</RepeatButton>
                        
          <RepeatButton Command="{x:Static local:NumericUpDown.DecreaseCommand}"
                        Grid.Column="1" Grid.Row="1">Down</RepeatButton>

        </Grid>

      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

다음 두 번째 반환 ItemsControl 바인딩 대상 요소부터 위쪽 경로에 오류가 발생 했습니다.

Binding myBinding = new Binding();
// Returns the second ItemsControl encountered on the upward path
// starting at the target element of the binding
myBinding.RelativeSource = new RelativeSource(
    RelativeSourceMode.FindAncestor, typeof(ItemsControl), 2);
Dim myBinding As New Binding()
' Returns the second ItemsControl encountered on the upward path
' starting at the target element of the binding
myBinding.RelativeSource = New RelativeSource(RelativeSourceMode.FindAncestor, GetType(ItemsControl), 2)

설명

바인딩 소스를 지정 하는 방법 중 하나를 사용 하는 것은 Binding.RelativeSource 속성입니다. 해당 속성의 속성 형식입니다. RelativeSource 태그 확장 구현 및 데이터 개체에 동시에 합니다. 확장 자체가 반환 될 때 (참조 ProvideValue), 데이터에 관련 정보가 포함 됩니다. 태그 확장의 주 목적은 특성 형식으로 가변 인수 생성자 구문을 허용 하는 것을 FindAncestor 모드 상위 항목 형식과 다른 모드 필요가 없는 수준에 대 한 두 개의 추가 인수를 사용 하 여 인라인으로 정의 될 수 있습니다.

XAML 정보는 RelativeSource MarkupExtension을 참조하세요.

생성자

RelativeSource()

RelativeSource 클래스의 새 인스턴스를 초기화합니다.

RelativeSource(RelativeSourceMode)

초기 모드로 RelativeSource 클래스의 새 인스턴스를 초기화합니다.

RelativeSource(RelativeSourceMode, Type, Int32)

초기 모드 및 원하는 상대 소스를 찾는 데 사용할 수 있는 추가 트리 탐색 한정자로 RelativeSource 클래스의 새 인스턴스를 초기화합니다.

속성

AncestorLevel

FindAncestor 모드에서 찾을 상위 항목의 수준을 가져오거나 설정합니다. 1은 바인딩 대상 요소에 가장 가까운 항목을 나타냅니다.

AncestorType

찾을 상위 항목의 형식을 가져오거나 설정합니다.

Mode

바인딩 대상의 위치를 기준으로 하여 바인딩 소스 위치를 설명하는 RelativeSourceMode 값을 가져오거나 설정합니다.

PreviousData

RelativeSource 모드에 대해 생성된 PreviousData를 반환하는 데 사용되는 정적 값을 가져옵니다.

Self

RelativeSource 모드에 대해 생성된 Self를 반환하는 데 사용되는 정적 값을 가져옵니다.

TemplatedParent

RelativeSource 모드에 대해 생성된 TemplatedParent를 반환하는 데 사용되는 정적 값을 가져옵니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ProvideValue(IServiceProvider)

이 태그 확장의 대상 개체 속성에 대한 값으로 설정해야 하는 개체를 반환합니다. RelativeSource의 경우 이 개체는 지정한 모드에 적절한 소스를 사용하는 다른 RelativeSource입니다.

ShouldSerializeAncestorLevel()

AncestorLevel 속성을 유지해야 하는지를 나타냅니다.

ShouldSerializeAncestorType()

AncestorType 속성을 유지해야 하는지를 나타냅니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

ISupportInitialize.BeginInit()

이 멤버는 WPF(Windows Presentation Foundation) 인프라를 지원하며 코드에서 직접 사용할 수 없습니다.

ISupportInitialize.EndInit()

이 멤버는 WPF(Windows Presentation Foundation) 인프라를 지원하며 코드에서 직접 사용할 수 없습니다.

적용 대상

추가 정보