Control.Template 屬性

定義

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

public:
 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.

範例

下列範例會建立 ButtonControlTemplateThe 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">
    <Setter.Value>
      <ControlTemplate TargetType="Button">
        <Grid>
          <Ellipse Fill="{TemplateBinding Background}"/>
          <ContentPresenter HorizontalAlignment="Center"
                            VerticalAlignment="Center"/>
        </Grid>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

備註

ControlTemplate 指定 Control的外觀;如果 Control 沒有 ControlTemplateControl 將不會出現在您的應用程式中。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
設定為 true 的中繼資料屬性Metadata properties set to true AffectsMeasure

適用於