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

속성 값

String

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

예제

다음 예제는 TabControl 컬렉션에 Student 개체입니다. Student 클래스에는 Name 속성, 컬렉션 Course 개체 및 구현를 IFormattable.ToString 반환 하는 방법을 Name 학생 또는 학생의 코스를 나열 하는 문자열입니다. 예제에서는 HeaderedContentControl.HeaderStringFormat 학생의 이름에 삽입할 합니다 HeaderTabItem (에서 상속 하는 HeaderedContentControl), 및 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

설명

ContentStringFormat 미리 정의 된, 복합 또는 사용자 지정 문자열 형식의 수 있습니다. 문자열 형식에 대 한 자세한 내용은 참조 하세요. 형식합니다. 설정 하는 경우는 ContentTemplate 또는 ContentTemplateSelector 의 한 TabControl, ContentStringFormat 속성은 무시 됩니다.

적용 대상