Control.Template Control.Template Control.Template Control.Template Property


取得或設定控制項範本。Gets or sets a control template.

 property System::Windows::Controls::ControlTemplate ^ Template { System::Windows::Controls::ControlTemplate ^ get(); void set(System::Windows::Controls::ControlTemplate ^ value); };
public System.Windows.Controls.ControlTemplate Template { get; set; }
member this.Template : System.Windows.Controls.ControlTemplate with get, set
Public Property Template As ControlTemplate


定義 Control 的外觀範本。The template that defines the appearance of the Control.


下列範例會建立ControlTemplate針對ButtonThe following example creates a ControlTemplate for a Button. 如果您的加入您的應用程式,做為資源,應用程式中的所有按鈕會顯示為 省略符號,但仍會為按鈕的函式。If you add this to your application as a resource, all the buttons in the application will appear as ellipses but will still function as buttons.

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


ControlTemplate指定的外觀Control; 如果Control沒有ControlTemplate,則Control不會出現在您的應用程式。The ControlTemplate specifies the appearance of a Control; if a Control does not have a ControlTemplate, the Control will not appear in your application. 控制項作者定義預設控制項範本,而且應用程式作者可以覆寫ControlTemplate重新定義控制項的視覺化樹狀結構。The control author defines the default control template, and the application author can override the ControlTemplate to redefine the visual tree of the control. 請參閱控制項的樣式和範本資訊和範例,示範如何變更現有控制項的視覺化樹狀結構。See Control Styles and Templates for information and examples of how to change the visual tree of existing controls.

AControlTemplate將不會察覺到外部使用者和物件,其中包括的實作詳細資料的自主的單位Style物件。A ControlTemplate is intended to be a self-contained unit of implementation detail that is invisible to outside users and objects, including Style objects. 管理控制項範本的內容的唯一方式是從相同的控制項範本。The only way to manipulate the content of the control template is from within the same control template.

相依性屬性資訊Dependency Property Information

識別項欄位Identifier field TemplateProperty
若要設定的中繼資料屬性 trueMetadata properties set to true AffectsMeasure