HeaderedContentControl.HeaderStringFormat Właściwość

Definicja

Pobiera lub ustawia ciąg złożony określający sposób formatowania Header właściwości, jeśli jest wyświetlany jako ciąg.

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, set
Public Property HeaderStringFormat As String

Wartość właściwości

Ciąg złożony określający sposób formatowania Header właściwości, jeśli jest wyświetlany jako ciąg. Wartość domyślna to null.

Atrybuty

Przykłady

Poniższy przykład wiąże obiekt z TabControl kolekcją Student obiektów. Klasa Student ma właściwość, kolekcję Course obiektów i implementuje IFormattable.ToString metodę Name zwracaną przez Name ucznia lub ciąg, który zawiera listę kursów ucznia. W przykładzie użyto HeaderStringFormat metody , aby umieścić nazwę ucznia w Header każdej z nich TabItem (która dziedziczy po HeaderedContentControl), a element TabControl.ContentStringFormat , aby wyświetlić listę kursów dla każdego ucznia w zawartości elementu 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>

Poniższy przykład implementuje metodę IFormattable.ToString , aby zwrócić ciąg Name studenta lub ciągu, który zawiera listę kursów ucznia.

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

Uwagi

HeaderStringFormat może być wstępnie zdefiniowanym, złożonym lub niestandardowym formatem ciągu. Aby uzyskać więcej informacji na temat formatów ciągów, zobacz Formatting Types (Typy formatowania). Jeśli ustawisz HeaderTemplate właściwość lub HeaderTemplateSelector elementu HeaderedContentControl, HeaderStringFormat właściwość zostanie zignorowana.

Informacje dotyczące właściwości zależności

Pole identyfikatora HeaderStringFormatProperty
Właściwości metadanych ustawione na true Brak

Dotyczy