Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

TextBlock.Padding Property

Gets or sets a value that indicates the thickness of padding space between the boundaries of the content area, and the content displayed by a TextBlock. This is a dependency property.

Namespace:  System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)

public Thickness Padding { get; set; }
    <Thickness .../>
<object Padding="uniformThickness"/>
- or -
<object Padding="independentThickness"/>
- or -
<object Padding="qualifiedUniformThickness"/>
- or -
<object Padding="qualifiedIndependentThickness"/>

XAML Values


String representation of a single Double value to apply uniformly to all four thickness dimensions. For example, a value of "10" is equivalent to a value of "10,10,10,10". An unqualified value is measured in device independent pixels. Strings need not explicitly include decimal points.


String representation of four ordered Double values corresponding to independent thickness dimensions for left, top, right, and bottom, in this order. The four values must be separated with commas; spaces are not allowed. For example, "5,10,15,20" results in 5 pixels of padding to the left of content, 10 pixels of padding above content, 15 pixels of padding to the right of content, and 20 pixels of padding below the content.


A value described by uniformThickness followed by one of the following unit specifiers: px, in.

px (default) is device-independent units (1/96th inch per unit)

in is inches; 1in==96px

For example, "1in" provides uniform padding of 1 inch in all directions.


A value described by independentThickness, with each independent value followed by one of the following unit specifiers: px, in.

px (default) is device-independent units (1/96th inch per unit)

in is inches; 1in==96px

For example, "1.5in,0.8in,1.5in,0.8in". Unit specifiers may be mixed or omitted from one or more values.

Property Value

Type: System.Windows.Thickness
A Thickness structure specifying the amount of padding to apply, in device independent pixels. The default is Double.NaN.

Identifier field


Metadata properties set to true


Padding can be described as uniform in all directions (Padding="10"), or as four distinct values that represent left, top, right, and bottom padding independently (Padding="5,0,10,20").

If a specified padding thickness exceeds the corresponding content area dimension (for example, the sum of the left and right padding widths exceeds the content area width), the thickness of the padding is proportionally reduced to be no greater than the relevant content area dimension.

The following example shows how to set the Padding attribute of a TextBlock element.



  FontFamily="Century Gothic"


  <Run Background="LightGreen">Text run 1.</Run>
  <LineBreak/><Run Background="LightBlue">Text run 2.</Run>
  <LineBreak/><Run Background="LightYellow">Text run 3.</Run>

The following example shows how to set the Padding property programmatically.

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;

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0
© 2018 Microsoft