HeaderedContentControl.HeaderStringFormat 属性     
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个撰写字符串,该字符串指定如果 Header 属性显示为字符串,应如何设置该属性的格式。
public:
 property System::String ^ HeaderStringFormat { System::String ^ get(); void set(System::String ^ value); };[System.ComponentModel.Bindable(true)]
public string HeaderStringFormat { get; set; }[<System.ComponentModel.Bindable(true)>]
member this.HeaderStringFormat : string with get, setPublic Property HeaderStringFormat As String属性值
一个撰写字符串,指定如果 Header 属性显示为字符串,应如何设置该属性的格式。 默认值为 null。
- 属性
示例
以下示例将 TabControl 绑定到 对象的集合 Student 。  类 Student 具有 Name 属性、对象的集合 Course ,并实现 IFormattable.ToString 方法以返回 Name 学生的 或列出学生课程的字符串。  该示例使用 HeaderStringFormat 将学生的姓名Header放在继承自 HeaderedContentControl) 的每个TabItem (中,并使用 TabControl.ContentStringFormat 在 的内容TabItem中显示每个学生的课程列表。
<Grid>
  <Grid.Resources>
    <src:Students x:Key="Students"/>
    <Style TargetType="TabItem">
      <Setter Property="HeaderStringFormat" Value="n"/>
      <Setter Property="FontFamily" Value="Lucida Sans Unicode"/>
      <Setter Property="Foreground" Value="Green"/>
      <Setter Property="FontWeight" Value="Bold"/>
    </Style>
  </Grid.Resources>
  <TabControl ItemsSource="{StaticResource Students}"
              FontFamily="Lucida Console" Foreground="Navy"
              ContentStringFormat="cl"/>
</Grid>
以下示例实现 IFormattable.ToString 方法以返回 Name 学生的 或列出学生课程的字符串。
public string ToString(string format, IFormatProvider formatProvider)
{
    // 'n': print the name only.
    if (format == "n")
    {
        return Name;
    }
    // 'cl': print the course list.
    if (format == "cl")
    {
        string stringFormat = "{0,-25}{1,-30}{2,-10}\r\n";
        StringBuilder str = new StringBuilder();
        str.AppendLine(); 
        str.AppendFormat(stringFormat, "Title", "Description", "ID");
        str.AppendLine(); 
        foreach (Course c in Courses)
        {
            str.AppendFormat(stringFormat, c.Title, c.Description, c.SectionID);
        }
        return str.ToString();
    }
    return this.ToString();
}
Public Overloads Function ToString(ByVal format As String, ByVal formatProvider As IFormatProvider) As String Implements IFormattable.ToString
    ' 'n': print the name only.
    If format = "n" Then
        Return Name
    End If
    ' 'cl': print the course list.
    If format = "cl" Then
        Dim stringFormat As String = "{0,-25}{1,-30}{2,-10}" & vbCrLf
        Dim str As New StringBuilder()
        str.AppendLine()
        str.AppendFormat(stringFormat, "Title", "Description", "ID")
        str.AppendLine()
        For Each c As Course In Courses
            str.AppendFormat(stringFormat, c.Title, c.Description, c.SectionID)
        Next c
        Return str.ToString()
    End If
    Return Me.ToString()
End Function
注解
HeaderStringFormat 可以是预定义、复合或自定义字符串格式。 有关字符串格式的详细信息,请参阅 格式设置类型。 如果设置 HeaderTemplate 的 或 HeaderTemplateSelector 属性 HeaderedContentControl,则会忽略 该 HeaderStringFormat 属性。
依赖项属性信息
| 标识符字段 | HeaderStringFormatProperty | 
| 元数据属性设置为 true | 无 |