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, set
Public Property HeaderStringFormat As String
屬性值
一個複合字串,指定若以字串顯示時,該如何格式化該 Header 屬性。 預設值為 null。
- 屬性
範例
以下範例將 a TabControl 綁定為一組 Student 物件。 該 Student 類別有一個 Name 屬性,即一組 Course 物件,並實作 IFormattable.ToString 回傳學生的 或 Name 列出學生課程的字串的方法。 範例中 將HeaderStringFormat學生姓名置於 HeaderTabItem 的 中(繼承自 HeaderedContentControl),並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 的 HeaderedContentControlHeaderStringFormat 或 HeaderTemplateSelector 屬性,該屬性會被忽略。
相依財產資訊
| 項目 | 價值 |
|---|---|
| 識別碼欄位 | HeaderStringFormatProperty |
元資料屬性設為 true |
沒有 |