Control.Template 屬性


取得或設定控制項範本。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.

是要做為 ControlTemplate 獨立的執行詳細資料單位,在使用者和物件之外並不可見,包括 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