ControlTemplate.TargetType 속성

정의

ControlTemplate이 사용되는 형식을 가져오거나 설정합니다.

public:
 property Type ^ TargetType { Type ^ get(); void set(Type ^ value); };
[System.Windows.Markup.Ambient]
public Type TargetType { get; set; }
[<System.Windows.Markup.Ambient>]
member this.TargetType : Type with get, set
Public Property TargetType As Type

속성 값

Type

기본값은 null입니다.

특성

예외

템플릿의 정의에 TargetType가 포함되어 있으면 ContentPresenter 속성은 null이 아니어야 합니다.

지정된 형식이 잘못된 경우. TargetTypeControlTemplateControl, Page 또는 PageFunctionBase이거나 여기에서 상속되어야 합니다.

예제

다음 예제에서는 이 속성을 사용하는 방법을 보여 줍니다.

<Style x:Key="{x:Type Label}"
       TargetType="Label">
  <Setter Property="HorizontalContentAlignment"
          Value="Left" />
  <Setter Property="VerticalContentAlignment"
          Value="Top" />
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="Label">
        <Border>
          <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            RecognizesAccessKey="True" />
        </Border>
        <ControlTemplate.Triggers>
          <Trigger Property="IsEnabled"
                   Value="false">
            <Setter Property="Foreground">
              <Setter.Value>
                <SolidColorBrush Color="{DynamicResource DisabledForegroundColor}" />
              </Setter.Value>
            </Setter>
          </Trigger>
        </ControlTemplate.Triggers>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

위의 예제에서는 다음 리소스를 사용합니다.

전체 샘플을 보려면 Styling with ControlTemplates Sample(ControlTemplate으로 스타일 지정 샘플)을 참조하세요.

설명

리소스 섹션에 속성이 형식으로 TargetType 설정된 독립 실행형 ControlTemplate 이 있는 경우 해당 형식 ControlTemplate 에 자동으로 적용되지 않습니다. 대신 템플릿을 지정 x:Key 하고 명시적으로 적용해야 합니다.

또한 템플릿 정의에 TargetType ControlTemplate .가 포함된 경우 속성이 ContentPresenter필요합니다.

XAML 특성 사용

<object  TargetType="typeName"/>  

XAML 값

typeName
클래스의 형식 이름입니다. 클래스의 Type 이름을 참조하려면 태그 확장 및 WPF XAML을 사용합니다.

적용 대상