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

屬性值

自動取別名時所使用的主檔名。 預設值為 "Content"。

範例

下列範例示範 的 樣式 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 ,才應該使用這個屬性。 當範本包含 ContentPresenterContentSource 設定為 「 Abc 」 的 時, ContentContentTemplateContentPresenter 、 和 ContentTemplateSelector 屬性會自動分別別名為 AbcAbcTemplate 和 。 AbcTemplateSelector 從 .NET Framework 3.5 Service Pack 1 開始,將 設定 ContentSource 為 「 Abc 」 也會使 ContentStringFormat 屬性別名為 AbcStringFormat

此屬性的兩個最實用值是 「Content」 和 「Header」。

相依性屬性資訊

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

適用於