이 문서는 기계로 번역한 것입니다. 원본 텍스트를 보려면 포인터를 문서의 문장 위로 올리십시오. 추가 정보
번역
원본
이 항목은 아직 평가되지 않았습니다.- 이 항목 평가

ControlTemplate 클래스

시각적 구조 및 동작 측면을 지정 된 Control 는 공유할 수 있습니다 컨트롤의 여러 인스턴스 간에.

네임스페이스:  System.Windows.Controls
어셈블리:  PresentationFramework(PresentationFramework.dll)
XAML의 XMLNS: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
[DictionaryKeyPropertyAttribute("TargetType")]
[LocalizabilityAttribute(LocalizationCategory.None, Readability = Readability.Unreadable)]
public class ControlTemplate : FrameworkTemplate
<ControlTemplate>
  <VisualTreeRootNode>
VisualTreeNodeContents
  </VisualTreeRootNode>
</ControlTemplate>

XAML 값

ControlTemplate

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

VisualTreeRootNode

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

VisualTreeNodeContents

사용할된 템플릿을 완료 하는 하나 이상의 요소입니다. 경우으로 선택 요소 VisualTreeRootNode 만 지 원하는 유일한 자식 요소인 다음 있을 수 있습니다만 한 요소 선언으로 VisualTreeNodeContents. 또한 경우 텍스트 콘텐트를 제공 하려면 (일반적으로 처럼) 있습니다 선택한 VisualTreeRootNode 텍스트 콘텐츠 속성을 지원 합니다.

ControlTemplate 형식에서는 다음과 같은 멤버를 노출합니다.

  이름설명
Public 메서드ControlTemplate()새 인스턴스 초기화를 ControlTemplate 클래스입니다.
Public 메서드ControlTemplate(Type)새 인스턴스를 초기화를 ControlTemplate 클래스를 지정 된 대상 형식입니다.
위쪽
  이름설명
Public 속성Dispatcher가져옵니다는 DispatcherDispatcherObject 와 관련 된. (DispatcherObject에서 상속됨)
Public 속성HasContent이 템플릿의 콘텐츠가 최적화 되어 있는지 여부를 나타내는 값을 가져옵니다. (FrameworkTemplate에서 상속됨)
Public 속성IsSealed변경할 수 없도록이 개체는 변경 불가능 상태 인지 여부를 나타내는 값을 가져옵니다. (FrameworkTemplate에서 상속됨)
Public 속성Resources이 템플릿의 범위 내에서 사용할 수 있는 리소스의 컬렉션을 가져오거나 설정 합니다. (FrameworkTemplate에서 상속됨)
Public 속성TargetType해당 형식을 가져오거나이를 ControlTemplate 위한 것입니다.
Public 속성Template기록 하거나 서식 파일을 정의 하거나 작성자가 적용 된 경우 템플릿 XAML 노드를 재생 하는 개체에 대 한 참조를 가져오거나 설정 합니다. (FrameworkTemplate에서 상속됨)
Public 속성Triggers컬렉션을 가져옵니다 TriggerBase 개체 속성 변경 사항을 적용 하거나 기반 작업을 수행할 조건을 지정 합니다.
Public 속성VisualTree템플릿의 루트 노드를 가져오거나 설정 합니다. (FrameworkTemplate에서 상속됨)
위쪽
  이름설명
Public 메서드CheckAccess호출 스레드가이 액세스를 포함할지 여부를 결정 DispatcherObject. (DispatcherObject에서 상속됨)
Public 메서드Equals(Object)지정한 개체와 현재 개체가 같은지 여부를 확인합니다. (Object에서 상속됨)
Protected 메서드Finalize

가비지 수집자 에서 회수하기 전에 개체에서 리소스를 해제하고 다른 정리 작업을 수행할 수 있게 합니다.

(Object에서 상속됨)
Public 메서드FindName이 템플릿 내에 정의 된 지정한 이름과 연관 된 요소를 찾습니다. (FrameworkTemplate에서 상속됨)
Public 메서드GetHashCode특정 형식에 대한 해시 함수 역할을 합니다. (Object에서 상속됨)
Public 메서드GetType현재 인스턴스의 Type을 가져옵니다. (Object에서 상속됨)
Public 메서드LoadContent템플릿의 콘텐츠를 개체의 인스턴스로 로드 하 고 콘텐츠의 루트 요소를 반환 합니다. (FrameworkTemplate에서 상속됨)
Protected 메서드MemberwiseClone현재 Object의 단순 복사본을 만듭니다. (Object에서 상속됨)
Public 메서드RegisterName현재 이름 범위에 새 이름/개체 쌍을 등록합니다. (FrameworkTemplate에서 상속됨)
Public 메서드Seal템플릿을 변경할 수 없도록 잠급니다. (FrameworkTemplate에서 상속됨)
Public 메서드ShouldSerializeResourcesSerialization 프로세스 값을 serialize 해야 하는지 여부를 나타내는 값을 반환의 Resources 속성을이 클래스의 인스턴스를 합니다. (FrameworkTemplate에서 상속됨)
Public 메서드ShouldSerializeVisualTreeSerialization 프로세스 값을 serialize 해야 하는지 여부를 나타내는 값을 반환의 VisualTree 속성을이 클래스의 인스턴스를 합니다. (FrameworkTemplate에서 상속됨)
Public 메서드ToString현재 개체를 나타내는 문자열을 반환합니다. (Object에서 상속됨)
Public 메서드UnregisterName이름/개체 매핑을 XAML 이름 범위에서 제거합니다. (FrameworkTemplate에서 상속됨)
Protected 메서드ValidateTemplatedParent규칙 집합에 대해 템플릿 부모를 확인합니다. (FrameworkTemplate.ValidateTemplatedParent(FrameworkElement)을(를) 재정의함)
Public 메서드VerifyAccess호출 스레드가이 권한이 적용 DispatcherObject. (DispatcherObject에서 상속됨)
위쪽
  이름설명
명시적 인터페이스 구현Private 메서드INameScope.FindName인프라입니다. 제공 된 식별 이름이 있는 개체를 반환 합니다. (FrameworkTemplate에서 상속됨)
명시적 인터페이스 구현Private 메서드IQueryAmbient.IsAmbientPropertyAvailable현재 범위에서 지정 된 앰비언트 속성을 사용할 수 있는지 여부를 쿼리 합니다. (FrameworkTemplate에서 상속됨)
위쪽

ControlTemplate 컨트롤의 시각적 구조를 지정할 수 있습니다. 컨트롤 작성자는 기본 ControlTemplate 응용 프로그램 작성자가 무시할 수 있습니다 해당 ControlTemplate 컨트롤의 시각적 구조를 다시 생성 합니다.

컨트롤 템플릿에 제공 되는 다양 한 기능 중 하나는 WPF 스타일 및 템플릿 모델입니다. 스타일 및 템플릿 모델 대부분의 사용자 컨트롤을 직접 작성할 필요가 없습니다 것이 뛰어난 유연성을 제공 합니다. 컨트롤의 시각화를 변경 하거나 대체 하는 응용 프로그램 작성자의 경우는 ControlTemplate 기존 컨트롤의 참조는 스타일 지정 및 템플릿 항목에 자세히 설명 하 고 예제에 대 한.

컨트롤을 직접 작성 하는 경우 "사용자 지정 컨트롤 만들기"를 참조를 컨트롤 제작 개요.

A ControlTemplate 외부 사용자 및 스타일 등의 개체를 볼 수 없습니다 구현 세부의 독립적인된 단위 수는 있습니다. 컨트롤이 템플릿 내용을 조작할 수 있는 유일한 방법은의 컨트롤 템플릿 내에서입니다.

다음은 ButtonStyle 설정의 ControlTemplateButton


<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 샘플

설정할 때의 Template 속성에는 ControlControlTemplate 위의 예제와 같이 전체 템플릿을 대체 됩니다. 무엇을 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>


참고 여기에 표시 되지 않은 리소스를 참조 하는이 예제입니다. 전체 샘플을 참조 하십시오. 스타일 지정 샘플 Controltemplates와. 샘플 컨트롤 템플릿 예제를 여러 가지 컨트롤을 제공 합니다 컨트롤 템플릿 만들기를 시작할 수 있는 가장 좋은 방법은.

.NET Framework

4.5, 4, 3.5, 3.0에서 지원

.NET Framework Client Profile

4, 3.5 SP1에서 지원

Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008(서버 코어 역할은 지원되지 않음), Windows Server 2008 R2(서버 코어 역할은 SP1 이상에서 지원, Itanium은 지원되지 않음)

.NET Framework에서 모든 플랫폼의 전체 버전을 지원하지는 않습니다. 지원되는 버전의 목록을 보려면 .NET Framework 시스템 요구 사항을 참조하십시오.
이 형식의 모든 공용 static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.
이 정보가 도움이 되었습니까?
(1500자 남음)

커뮤니티 추가 항목

추가
Microsoft는 MSDN 웹 사이트에 대한 귀하의 의견을 이해하기 위해 온라인 설문 조사를 진행하고 있습니다. 참여하도록 선택하시면 MSDN 웹 사이트에서 나가실 때 온라인 설문 조사가 표시됩니다.

참여하시겠습니까?
© 2013 Microsoft. All rights reserved.