Sdílet prostřednictvím


HeaderedContentControl.HeaderStringFormat Vlastnost

Definice

Získá nebo nastaví složený řetězec, který určuje, jak formátovat Header vlastnost, pokud je zobrazen jako řetězec.

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

Hodnota vlastnosti

Složený řetězec, který určuje, jak formátovat Header vlastnost, pokud se zobrazí jako řetězec. Výchozí hodnota je null.

Atributy

Příklady

Následující příklad vytvoří vazbu na TabControl kolekci Student objektů. Třída StudentName vlastnost, kolekci Course objektů a implementuje IFormattable.ToString metodu pro vrácení Name studenta nebo řetězce, který obsahuje seznam kurzů studenta. Příklad používá HeaderStringFormat k vložení jména studenta do Header každého z nich TabItem (který dědí) HeaderedContentControla TabControl.ContentStringFormat k zobrazení seznamu kurzů pro každého studenta v obsahu předmětu 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>

Následující příklad implementuje metodu IFormattable.ToString pro vrácení buď Name studenta, nebo řetězce, který obsahuje seznam kurzů studenta.

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

Poznámky

HeaderStringFormat může být předdefinovaný, složený nebo vlastní formát řetězce. Další informace o formátech řetězců naleznete v tématu Typy formátování. Pokud nastavíte HeaderTemplate vlastnost nebo HeaderTemplateSelector vlastnost HeaderedContentControl, HeaderStringFormat bude tato vlastnost ignorována.

Informace o vlastnosti závislosti

Položka Hodnota
Pole Identifikátor HeaderStringFormatProperty
Vlastnosti metadat nastavené na true None

Platí pro