ContentControl.ContentStringFormat 屬性

定義

取得或設定複合字串,這個字串會指定在 Content 屬性顯示為字串的情況下,如何格式化這個屬性。

public:
 property System::String ^ ContentStringFormat { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.Bindable(true)]
public string ContentStringFormat { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.ContentStringFormat : string with get, set
Public Property ContentStringFormat As String

屬性值

複合字串,指定在 Content 屬性顯示為字串的情況下,如何格式化這個屬性。

屬性

範例

下列範例會藉由在 中設定 屬性,並將 套用 Style 至繼承自 ContentControl 的兩 Label 個 物件,以指定 物件的格式 DateTimeContentStringFormatStyle

<StackPanel
  xmlns:sys="clr-namespace:System;assembly=mscorlib">

  <StackPanel.Resources>
    <Style x:Key="DateLabel" TargetType="Label">
      <Setter Property="ContentStringFormat" Value="dddd – d - MMMM"/>
    </Style>
  </StackPanel.Resources>

  <!--The results when the default culture is en-US
      is March 4, 2005.-->
  <Label Style="{StaticResource DateLabel}">
    <sys:DateTime>2004/3/4 13:6:55</sys:DateTime>
  </Label>

  <Label Style="{StaticResource DateLabel}">
    <x:Static Member="sys:DateTime.Now"/>
  </Label>

</StackPanel>

備註

ContentStringFormat 可以是預先定義的、複合或自訂字串格式。 如需字串格式的詳細資訊,請參閱 格式化類型。 如果您設定 ContentTemplateContentControlContentTemplateSelector 屬性,則會 ContentStringFormat 忽略 屬性。

適用於