ContentControl.ContentStringFormat 屬性
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定複合字串,這個字串會指定在 Content 屬性顯示為字串的情況下,如何格式化這個屬性。
public:
property System::String ^ ContentStringFormat { System::String ^ get(); void set(System::String ^ value); };
C#
[System.ComponentModel.Bindable(true)]
public string ContentStringFormat { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.ContentStringFormat : string with get, set
Public Property ContentStringFormat As String
複合字串,指定在 Content 屬性顯示為字串的情況下,如何格式化這個屬性。
- 屬性
下列範例會藉由在 中設定 屬性,並將 套用 Style 至繼承自 ContentControl 的兩 Label 個 物件,以指定 物件的格式 DateTime 。 ContentStringFormatStyle
XAML
<StackPanel
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<StackPanel.Resources>
<Style x:Key="DateLabel" TargetType="Label">
<Setter Property="ContentStringFormat" Value="dddd – d - MMMM"/>
</Style>
</StackPanel.Resources>
<!--The results when the default culture is en-US
is March 4, 2005.-->
<Label Style="{StaticResource DateLabel}">
<sys:DateTime>2004/3/4 13:6:55</sys:DateTime>
</Label>
<Label Style="{StaticResource DateLabel}">
<x:Static Member="sys:DateTime.Now"/>
</Label>
</StackPanel>
ContentStringFormat 可以是預先定義的、複合或自訂字串格式。 如需字串格式的詳細資訊,請參閱 格式化類型。 如果您設定 ContentTemplate 的 ContentControl 或 ContentTemplateSelector 屬性,則會 ContentStringFormat 忽略 屬性。
產品 | 版本 |
---|---|
.NET Framework | 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9, 10 |