語言

ContentPresenter.ContentSource 屬性

定義

取得或設定自動別名期間要使用的基底名稱。

public:
 property System::String ^ ContentSource { System::String ^ get(); void set(System::String ^ value); };
public string ContentSource { get; set; }
member this.ContentSource : string with get, set
Public Property ContentSource As String

屬性值

自動混疊時應使用的基礎名稱。 預設是「內容」。

範例

以下範例展示了一個 的 HeaderedContentControl 樣式,用以展示該 ContentSource 性質的使用方式:

<Style TargetType="HeaderedContentControl">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="{x:Type HeaderedContentControl}">
        <StackPanel>
          <Grid>
            <Rectangle Stroke="{TemplateBinding Background}"/>
            <ContentPresenter ContentSource="Header"/>
          </Grid>
          <Grid>
            <Rectangle Fill="{TemplateBinding Background}"/>
            <ContentPresenter ContentSource="Content"/>
          </Grid>
        </StackPanel>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

備註

這個屬性只應該在 在範本 ContentPresenter 中時使用。 當模板包含 ContentPresenter 且 ContentSource 設為「Abc」時,Content該ContentTemplate模板的 、 ContentTemplateSelector及ContentPresenter屬性會自動分別別名為 Abc、 AbcTemplate、 和 AbcTemplateSelector。 從 .NET Framework 3.5 Service Pack 1 開始,設定 ContentSource 為「Abc」也會使 ContentStringFormat 屬性被鋸齒化為 AbcStringFormat。

這個屬性最有用的兩個值是「Content」和「Header」。

相依財產資訊

Item 價值觀
識別碼欄位 ContentSourceProperty
元資料屬性設為 true None

適用於