다음을 통해 공유


TabControl.ContentStringFormat 속성

정의

개체가 문자열로 표시되는 경우 개체 내용의 서식을 TabItem 지정하는 방법을 지정하는 복합 문자열을 가져옵니다.

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

속성 값

개체가 문자열로 표시되는 경우 개체 내용의 서식을 TabItem 지정하는 방법을 지정하는 복합 문자열입니다.

예제

다음 예제에서는 개체 컬렉션 Student 에 바인딩 TabControl 합니다. 클래스에는 StudentName 속성, 개체 컬렉션 Course 이 있으며 학생의 과정 또는 학생의 과정을 나열하는 문자열을 반환 Name 하는 메서드를 구현 IFormattable.ToString 합니다. 이 예제에서는 각 TabItem 학생의 이름(상속 대상)에 HeaderedContentControl학생 이름을 Header 배치하고 ContentStringFormat 각 학생의 과정 목록을 콘텐츠에 TabItem표시하는 데 사용합니다HeaderedContentControl.HeaderStringFormat.

<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>

다음 예제에서는 학생의 과정 또는 학생의 과정을 나열하는 문자열을 반환 Name 하는 메서드를 구현 IFormattable.ToString 합니다.

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

설명

ContentStringFormat 는 미리 정의된, 복합 또는 사용자 지정 문자열 형식일 수 있습니다. 문자열 형식에 대한 자세한 내용은 형식 서식을 참조하세요. 설정하거나 ContentTemplateSelectorTabControl설정 ContentTemplate 하면 속성이 ContentStringFormat 무시됩니다.

적용 대상