ControlTemplate 클래스

정의

컨트롤의 여러 인스턴스에서 공유할 수 있는 Control의 표시 구조 및 동작 측면을 지정합니다.

public ref class ControlTemplate : System::Windows::FrameworkTemplate
[System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability=System.Windows.Readability.Unreadable)]
[System.Windows.Markup.DictionaryKeyProperty("TargetType")]
public class ControlTemplate : System.Windows.FrameworkTemplate
[<System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability=System.Windows.Readability.Unreadable)>]
[<System.Windows.Markup.DictionaryKeyProperty("TargetType")>]
type ControlTemplate = class
    inherit FrameworkTemplate
Public Class ControlTemplate
Inherits FrameworkTemplate
상속
특성

예제

다음은 다음의 집합을 ControlTemplate 보여 Button Style 주는 것입니다.Button

<Style TargetType="Button">
  <!--Set to true to not get any properties from the themes.-->
  <Setter Property="OverridesDefaultStyle" Value="True"/>
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="Button">
        <Grid>
          <Ellipse Fill="{TemplateBinding Background}"/>
          <ContentPresenter HorizontalAlignment="Center"
                            VerticalAlignment="Center"/>
        </Grid>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

이 항목이 적용 Button 되면 다음과 같이 Ellipse표시됩니다.

단추 ControlTemplate 샘플

위의 예제에서와 같이 a Control 의 속성을 새 ControlTemplate 속성으로 설정 Template 하면 전체 템플릿이 바꿔집니다. 포커스가 Button 있거나 누를 때의 모양은 모두 대체하려는 단추의 기본 모양에 해당합니다. 따라서 다음 예제와 같이 필요에 따라 단추를 누를 때의 모양 등을 정의에 넣을 수 있습니다.

<Style TargetType="Button">
  <Setter Property="SnapsToDevicePixels"
          Value="true" />
  <Setter Property="OverridesDefaultStyle"
          Value="true" />
  <Setter Property="FocusVisualStyle"
          Value="{StaticResource ButtonFocusVisual}" />
  <Setter Property="MinHeight"
          Value="23" />
  <Setter Property="MinWidth"
          Value="75" />
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="Button">
        <Border TextBlock.Foreground="{TemplateBinding Foreground}"
                x:Name="Border"
                CornerRadius="2"
                BorderThickness="1">
          <Border.BorderBrush>
            <LinearGradientBrush StartPoint="0,0"
                                 EndPoint="0,1">
              <LinearGradientBrush.GradientStops>
                <GradientStopCollection>
                  <GradientStop Color="{DynamicResource BorderLightColor}"
                                Offset="0.0" />
                  <GradientStop Color="{DynamicResource BorderDarkColor}"
                                Offset="1.0" />
                </GradientStopCollection>
              </LinearGradientBrush.GradientStops>
            </LinearGradientBrush>

          </Border.BorderBrush>
          <Border.Background>
            <LinearGradientBrush EndPoint="0.5,1"
                                 StartPoint="0.5,0">
              <GradientStop Color="{DynamicResource ControlLightColor}"
                            Offset="0" />
              <GradientStop Color="{DynamicResource ControlMediumColor}"
                            Offset="1" />
            </LinearGradientBrush>
          </Border.Background>
          <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="CommonStates">
              <VisualStateGroup.Transitions>
                <VisualTransition GeneratedDuration="0:0:0.5" />
                <VisualTransition GeneratedDuration="0"
                                  To="Pressed" />
              </VisualStateGroup.Transitions>
              <VisualState x:Name="Normal" />
              <VisualState x:Name="MouseOver">
                <Storyboard>
                  <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).
                      (GradientBrush.GradientStops)[1].(GradientStop.Color)"
                                                Storyboard.TargetName="Border">
                    <EasingColorKeyFrame KeyTime="0"
                                         Value="{StaticResource ControlMouseOverColor}" />
                  </ColorAnimationUsingKeyFrames>
                </Storyboard>
              </VisualState>
              <VisualState x:Name="Pressed">
                <Storyboard>
                  <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).
                      (GradientBrush.GradientStops)[1].(GradientStop.Color)"
                                                Storyboard.TargetName="Border">
                    <EasingColorKeyFrame KeyTime="0"
                                         Value="{StaticResource ControlPressedColor}" />
                  </ColorAnimationUsingKeyFrames>
                  <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.BorderBrush).
                      (GradientBrush.GradientStops)[0].(GradientStop.Color)"
                                                Storyboard.TargetName="Border">
                    <EasingColorKeyFrame KeyTime="0"
                                         Value="{StaticResource PressedBorderDarkColor}" />
                  </ColorAnimationUsingKeyFrames>
                  <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.BorderBrush).
                      (GradientBrush.GradientStops)[1].(GradientStop.Color)"
                                                Storyboard.TargetName="Border">
                    <EasingColorKeyFrame KeyTime="0"
                                         Value="{StaticResource PressedBorderLightColor}" />
                  </ColorAnimationUsingKeyFrames>
                </Storyboard>
              </VisualState>
              <VisualState x:Name="Disabled">
                <Storyboard>
                  <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).
                      (GradientBrush.GradientStops)[1].(GradientStop.Color)"
                                                Storyboard.TargetName="Border">
                    <EasingColorKeyFrame KeyTime="0"
                                         Value="{StaticResource DisabledControlDarkColor}" />
                  </ColorAnimationUsingKeyFrames>
                  <ColorAnimationUsingKeyFrames
                      Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)"
                                                Storyboard.TargetName="Border">
                    <EasingColorKeyFrame KeyTime="0"
                                         Value="{StaticResource DisabledForegroundColor}" />
                  </ColorAnimationUsingKeyFrames>
                  <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.BorderBrush).
                      (GradientBrush.GradientStops)[1].(GradientStop.Color)"
                                                Storyboard.TargetName="Border">
                    <EasingColorKeyFrame KeyTime="0"
                                         Value="{StaticResource DisabledBorderDarkColor}" />
                  </ColorAnimationUsingKeyFrames>
                </Storyboard>
              </VisualState>
            </VisualStateGroup>
          </VisualStateManager.VisualStateGroups>
          <ContentPresenter Margin="2"
                            HorizontalAlignment="Center"
                            VerticalAlignment="Center"
                            RecognizesAccessKey="True" />
        </Border>
        <ControlTemplate.Triggers>
          <Trigger Property="IsDefault"
                   Value="true">

            <Setter TargetName="Border"
                    Property="BorderBrush">
              <Setter.Value>
                <LinearGradientBrush StartPoint="0,0"
                                     EndPoint="0,1">
                  <GradientBrush.GradientStops>
                    <GradientStopCollection>
                      <GradientStop Color="{DynamicResource DefaultBorderBrushLightBrush}"
                                    Offset="0.0" />
                      <GradientStop Color="{DynamicResource DefaultBorderBrushDarkColor}"
                                    Offset="1.0" />
                    </GradientStopCollection>
                  </GradientBrush.GradientStops>
                </LinearGradientBrush>

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

이 예제에서는 여기에 표시되지 않는 리소스를 참조합니다. 전체 샘플을 보려면 Styling with ControlTemplates Sample(ControlTemplate으로 스타일 지정 샘플)을 참조하세요. 이 샘플은 여러 컨트롤에 대한 컨트롤 템플릿의 예를 제공하며 컨트롤 템플릿 만들기를 시작하는 가장 좋은 방법입니다.

설명

컨트롤 ControlTemplate 의 시각적 구조를 지정할 수 있습니다. 컨트롤 작성자는 기본값을 정의할 수 있습니다 ControlTemplate 애플리케이션 작성자 재정의할 수는 ControlTemplate 컨트롤의 시각적 구조를 재구성 하 합니다.

컨트롤 템플릿은 WPF 스타일 지정 및 템플릿 모델에서 제공하는 많은 기능 중 하나입니다. 스타일 지정 및 템플릿 모델은 많은 경우 사용자 고유의 컨트롤을 작성할 필요가 없는 뛰어난 유연성을 제공합니다. 애플리케이션 작성자가 컨트롤의 시각화를 변경 하거나 대체 하는 경우는 ControlTemplate 기존 컨트롤을 참조 합니다 스타일 및 템플릿 예제 및 자세한 내용은 항목입니다.

사용자 고유의 컨트롤을 작성하는 경우 컨트롤 작성 개요에서 "사용자 지정 컨트롤 만들기"를 참조하세요.

A ControlTemplate 는 스타일을 포함하여 외부 사용자 및 개체에 보이지 않는 자체 포함 구현 세부 정보 단위로 사용됩니다. 동일한 컨트롤 템플릿 내에서 컨트롤 템플릿의 콘텐츠를 조작 하는 유일한 방법은에서 됩니다.

XAML 속성 요소 사용

<ControlTemplate>  
  <VisualTreeRootNode>
    VisualTreeNodeContents  
  </VisualTreeRootNode>  
</ControlTemplate>  

XAML 값

ControlTemplate
파생 클래스에 대한 ControlTemplate 개체 요소입니다.

VisualTreeRootNode
단일 XAML 요소(또는 파생 클래스)의 ControlTemplate 직계 자식입니다. 템플릿에는 단일 루트 노드가 있어야 합니다. 유용한 템플릿을 생성하기 위해 VisualTreeRootNode 로 선택한 요소는 여러 자식 요소를 지원하는 모델인 자체 콘텐츠 모델을 지원해야 합니다.

VisualTreeNodeContents
원하는 템플릿을 완료하는 하나 이상의 요소입니다. VisualTreeRootNode 로 선택한 요소가 단일 자식만 지원하는 경우 VisualTreeNodeContents 로 선언된 요소는 하나만 있을 수 있습니다. 선택한 VisualTreeRootNode 가 텍스트 콘텐츠 속성을 지원하는 경우 텍스트 콘텐츠를 제공할 수도 있습니다(일반적이지는 않지만).

생성자

ControlTemplate()

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

ControlTemplate(Type)

지정된 대상 형식을 사용하여 ControlTemplate 클래스의 새 인스턴스를 초기화합니다.

속성

Dispatcher

Dispatcher와 연결된 DispatcherObject를 가져옵니다.

(다음에서 상속됨 DispatcherObject)
HasContent

이 템플릿의 콘텐츠가 최적화되어 있는지 여부를 나타내는 값을 가져옵니다.

(다음에서 상속됨 FrameworkTemplate)
IsSealed

이 개체가 변경할 수 없는 변경 불가능 상태인지 여부를 나타내는 값을 가져옵니다.

(다음에서 상속됨 FrameworkTemplate)
Resources

이 템플릿의 범위 내에서 사용할 수 있는 리소스의 컬렉션을 가져오거나 설정합니다.

(다음에서 상속됨 FrameworkTemplate)
TargetType

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

Template

작성자가 템플릿을 정의하거나 적용할 때 해당 템플릿의 XAML 노드를 기록/재생하는 개체에 대한 참조를 가져오거나 설정합니다.

(다음에서 상속됨 FrameworkTemplate)
Triggers

속성 변경 내용을 적용하거나 지정된 조건에 따라 작업을 수행하는 TriggerBase 개체 컬렉션을 가져옵니다.

VisualTree

템플릿의 루트 노드를 가져오거나 설정합니다.

(다음에서 상속됨 FrameworkTemplate)

메서드

CheckAccess()

호출 스레드가 이 DispatcherObject에 액세스할 수 있는지 여부를 확인합니다.

(다음에서 상속됨 DispatcherObject)
Equals(Object)

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

(다음에서 상속됨 Object)
FindName(String, FrameworkElement)

이 템플릿 내에 정의된 지정한 이름과 연결된 요소를 찾습니다.

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

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

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

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

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

템플릿의 콘텐츠를 개체의 인스턴스로 로드하고 콘텐츠의 루트 요소를 반환합니다.

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

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

(다음에서 상속됨 Object)
RegisterName(String, Object)

현재 이름 범위에 새 이름/개체 쌍을 등록합니다.

(다음에서 상속됨 FrameworkTemplate)
Seal()

템플릿을 변경할 수 없도록 잠급니다.

(다음에서 상속됨 FrameworkTemplate)
ShouldSerializeResources(XamlDesignerSerializationManager)

이 클래스의 인스턴스에서 serialization 프로세스를 통해 Resources 속성의 값을 serialize해야 하는지 여부를 나타내는 값을 반환합니다.

(다음에서 상속됨 FrameworkTemplate)
ShouldSerializeVisualTree()

이 클래스의 인스턴스에서 serialization 프로세스를 통해 VisualTree 속성의 값을 serialize해야 하는지 여부를 나타내는 값을 반환합니다.

(다음에서 상속됨 FrameworkTemplate)
ToString()

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

(다음에서 상속됨 Object)
UnregisterName(String)

XAML 이름 범위에서 이름/개체 매핑을 제거합니다.

(다음에서 상속됨 FrameworkTemplate)
ValidateTemplatedParent(FrameworkElement)

규칙 집합에 대해 템플릿 부모를 확인합니다.

VerifyAccess()

호출 스레드에서 이 DispatcherObject에 액세스할 수 있는지 확인합니다.

(다음에서 상속됨 DispatcherObject)

명시적 인터페이스 구현

INameScope.FindName(String)

지정된 식별 이름이 있는 개체를 반환합니다.

(다음에서 상속됨 FrameworkTemplate)
IQueryAmbient.IsAmbientPropertyAvailable(String)

지정된 앰비언트 속성을 현재 범위에서 사용할 수 있는지 여부를 쿼리합니다.

(다음에서 상속됨 FrameworkTemplate)

적용 대상

추가 정보