ContentControl.ContentStringFormat プロパティ

定義

Content プロパティが文字列として表示される場合に、その書式を指定する複合文字列を取得または設定します。

C#
[System.ComponentModel.Bindable(true)]
public string ContentStringFormat { get; set; }

プロパティ値

Content プロパティが文字列として表示される場合に、その書式を指定する複合文字列。

属性

次のDateTime例では、 で Style プロパティをContentStringFormat設定し、 を継承ContentControlする 2 つのLabelオブジェクトに を適用Styleすることで、オブジェクトの形式を指定します。

XAML
<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 には、定義済み、複合、またはカスタムの文字列形式を指定できます。 文字列形式の詳細については、「 型の書式設定」を参照してください。 の または ContentTemplateSelector プロパティをContentTemplateContentControl設定した場合、ContentStringFormatプロパティは無視されます。

適用対象

製品 バージョン
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10