TextBlock.Padding 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定一個值,表示內容區域邊界與內容之間 TextBlock填充空間的厚度,而 則顯示的內容。
public:
property System::Windows::Thickness Padding { System::Windows::Thickness get(); void set(System::Windows::Thickness value); };
public System.Windows.Thickness Padding { get; set; }
member this.Padding : System.Windows.Thickness with get, set
Public Property Padding As Thickness
屬性值
一個 Thickness 結構,指定應套用的填充量,單位為裝置無關像素。 預設值為 NaN。
範例
以下範例說明如何設定 Padding 元素 TextBlock 的屬性。
<TextBlock
Name="textBlock"
Background="AntiqueWhite"
Foreground="Navy"
FontFamily="Century Gothic"
FontSize="12"
FontStretch="UltraExpanded"
FontStyle="Italic"
FontWeight="UltraBold"
LineHeight="Auto"
Padding="5,10,5,10"
TextAlignment="Center"
TextWrapping="Wrap"
Typography.NumeralStyle="OldStyle"
Typography.SlashedZero="True"
>
<Run Background="LightGreen">Text run 1.</Run>
<LineBreak/><Run Background="LightBlue">Text run 2.</Run>
<LineBreak/><Run Background="LightYellow">Text run 3.</Run>
</TextBlock>
下列示範如何以程式設計的方式設定 Typography 屬性。
TextBlock textBlock = new TextBlock(new Run("A bit of text content..."));
textBlock.Background = Brushes.AntiqueWhite;
textBlock.Foreground = Brushes.Navy;
textBlock.FontFamily = new FontFamily("Century Gothic");
textBlock.FontSize = 12;
textBlock.FontStretch = FontStretches.UltraExpanded;
textBlock.FontStyle = FontStyles.Italic;
textBlock.FontWeight = FontWeights.UltraBold;
textBlock.LineHeight = Double.NaN;
textBlock.Padding = new Thickness(5, 10, 5, 10);
textBlock.TextAlignment = TextAlignment.Center;
textBlock.TextWrapping = TextWrapping.Wrap;
textBlock.Typography.NumeralStyle = FontNumeralStyle.OldStyle;
textBlock.Typography.SlashedZero = true;
Dim textBlock As New TextBlock(New Run("A bit of text content..."))
textBlock.Background = Brushes.AntiqueWhite
textBlock.Foreground = Brushes.Navy
textBlock.FontFamily = New FontFamily("Century Gothic")
textBlock.FontSize = 12
textBlock.FontStretch = FontStretches.UltraExpanded
textBlock.FontStyle = FontStyles.Italic
textBlock.FontWeight = FontWeights.UltraBold
textBlock.LineHeight = Double.NaN
textBlock.Padding = New Thickness(5, 10, 5, 10)
textBlock.TextAlignment = TextAlignment.Center
textBlock.TextWrapping = TextWrapping.Wrap
textBlock.Typography.NumeralStyle = FontNumeralStyle.OldStyle
textBlock.Typography.SlashedZero = True
備註
Padding 可以描述為所有方向Padding="10"均勻(),或描述為四個獨立代表左、上、右、底填充的值(Padding="5,0,10,20")。
若指定的填充厚度超過相應的內容區域尺寸(例如左右填充寬度的總和超過內容區域寬度),填充厚度會按比例減少,不超過相關內容區域尺寸。
XAML 屬性使用方式
<object Padding="uniformThickness"/>
- or -
<object Padding="independentThickness"/>
- or -
<object Padding="qualifiedUniformThickness"/>
- or -
<object Padding="qualifiedIndependentThickness"/>
XAML 值
均勻厚度 單一值的串表示 Double 法,以均勻適用於所有四個厚度維度。 例如,的"10"值等價於的值。"10,10,10,10" 未限定值以裝置獨立像素為單位。 字串不必明確包含小數點。
獨立厚度 四個有 Double 序值的串表示法,分別對應左、上、右、下四大厚度的獨立尺寸,依序如下。 四個值必須以逗號分隔;不允許有空位。 例如,「5、10、15、20」會在內容左側產生 5 像素的填充,內容上方有 10 像素的填充,內容右側有 15 像素的填充,內容下方則有 20 像素的填充。
合格均勻厚度 一個由 uniformThickness 描述的值,後接以下其中一個單位指定符: px, in。
px (預設)為裝置無關單位(每單位 1/96 吋)
in 是英吋;1in==96px
例如,提供 "1in" 各方向均1英吋的填充。
已確定獨立厚度 一個由 independentThickness 描述的值,每個獨立值後面跟著以下單位指定符之一: px, in。
px (預設)為裝置無關單位(每單位 1/96 吋)
in 是英吋;1in==96px
例如: "1.5in,0.8in,1.5in,0.8in" 。 單位指定符可以混用或省略於一個或多個值中。
相依財產資訊
| 項目 | 價值 |
|---|---|
| 識別碼欄位 | PaddingProperty |
元資料屬性設為 true |
AffectsMeasure |