TextBlock.Padding 屬性

定義

取得或設定值,指出內容區域界限和 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>

下列範例示範如何以程式設計方式設定 Padding 屬性。

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

<object Padding="uniformThickness"/>  
- or -  
<object Padding="independentThickness"/>  
- or -  
<object Padding="qualifiedUniformThickness"/>  
- or -  
<object Padding="qualifiedIndependentThickness"/>  

XAML 值

uniformThickness
Double 一值的字串表示,以統一套用至所有四個粗細維度。 例如, 的值 "10" 相當於 的值 "10,10,10,10" 。 不合格的值是以裝置獨立圖元來測量。 字串不需要明確包含小數點。

independentThickness
四個排序 Double 值的字串表示,以這個順序對應至左、上、右和下的獨立粗細維度。 這四個值必須以逗號分隔;不允許空格。 例如,「5,10,15,20」 會導致內容左邊的填補 5 圖元、內容上方 10 圖元的邊框間距、內容右邊 15 圖元的填補,以及內容下方 20 圖元的填補。

qualifiedUniformThickness
由 uniformThickness所描述的值,後面接著下列其中一個單位規範: pxin

px (預設) 是裝置獨立單位 (,每單位 1/96 英吋)

in 為英吋;1in==96px

例如, "1in" 提供所有方向的統一邊框間距 1 英吋。

qualifiedIndependentThickness
independentThickness所描述的值,每個獨立值後面接著下列其中一個單位規範: pxin

px (預設) 是裝置獨立單位 (,每單位 1/96 英吋)

in 為英吋;1in==96px

例如: "1.5in,0.8in,1.5in,0.8in" 。 單位規範可以混合或省略一或多個值。

相依性屬性資訊

識別碼欄位 PaddingProperty
設定為 的中繼資料屬性 true AffectsMeasure

適用於