다음을 통해 공유


RelativeSource.TemplatedParent 속성

정의

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

public:
 static property System::Windows::Data::RelativeSource ^ TemplatedParent { System::Windows::Data::RelativeSource ^ get(); };
public static System.Windows.Data.RelativeSource TemplatedParent { get; }
static member TemplatedParent : System.Windows.Data.RelativeSource
Public Shared ReadOnly Property TemplatedParent As RelativeSource

속성 값

정적 RelativeSource.

예제

다음 예제에서는 호출 NumericUpDownStyle 사용자 지정 컨트롤의 정의를 보여 있습니다. 이 Text 경우 적용되는 컨트롤인 개체의 속성 TextBlock 이 개체TemplatedParentNumericUpDown 속성 Style 에 바인딩 Value 됩니다.

<!--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>

설명

4개의 RelativeSourceMode 값 중 3개(Self또는TemplatedParent)는 고유한 프라이빗 값PreviousData이 없는 정적 값을 생성 RelativeSource 할 수 있습니다. 정적 속성의 모든 사용은 동일한 개체를 공유할 수 있으므로 각 용도에 대해 별도의 개체를 할당할 필요가 없습니다. 따라서 정적 속성을 사용하면 메모리 사용량이 줄어듭니다.

XAML 텍스트 사용

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

적용 대상

추가 정보