ContentControl.ContentStringFormat ContentControl.ContentStringFormat ContentControl.ContentStringFormat ContentControl.ContentStringFormat Property

定义

获取或设置一个撰写字符串,该字符串指定如果 Content 属性显示为字符串,应如何设置该属性的格式。Gets or sets a composite string that specifies how to format the Content property if it is displayed as a string.

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

属性值

一个撰写字符串,指定如果 Content 属性显示为字符串,应如何设置该属性的格式。A composite string that specifies how to format the Content property if it is displayed as a string.

示例

下面的示例通过DateTime Style ContentStringFormat 在中Label设置属性并将应用ContentControl于两个对象(继承自)来指定对象的格式。StyleThe following example specifies the format of DateTime objects by setting the ContentStringFormat property in a Style and applying the Style to two Label objects, which inherit from ContentControl.

<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可以是预定义的复合字符串格式。ContentStringFormat can be a predefined, composite, or custom string format. 有关字符串格式的详细信息, 请参阅格式设置类型For more information about string formats, see Formatting Types. 如果设置ContentTemplateContentTemplateSelectorContentControl的属性,则ContentStringFormat将忽略属性。If you set the ContentTemplate or ContentTemplateSelector property of a ContentControl, the ContentStringFormat property is ignored.

适用于