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

屬性值

ControlTemplate

定義 Control 的外觀範本。

範例

下列範例會 ControlTemplate 建立 的 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>

備註

ControlTemplate 指定 的外觀 Control ;如果 Control 沒有 ControlTemplate ,則 Control 不會出現在您的應用程式中。 控制項作者會定義預設控制項範本,而應用程式作者可以覆寫 ControlTemplate 來重新定義控制項的視覺化樹狀結構。 如需如何變更現有控制項視覺化樹狀結構的資訊和範例,請參閱 控制項樣式和範本

ControlTemplate是一個獨立實作詳細資料單位,在使用者和物件外部看不到,包括 Style 物件。 操作控制項範本內容的唯一方式是在相同的控制項範本內。

相依性屬性資訊

識別碼欄位 TemplateProperty
設定為 的中繼資料屬性 true AffectsMeasure

適用於