Padding Property
Collapse the table of content
Expand the table of content

Border.Padding Property

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Gets or sets the distance between the border and its child object.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.

public Thickness Padding { get; set; }
<Border Padding="uniform"/>
- or -
<Border Padding="left&right,top&bottom"/>
- or -
<Border Padding="left,top,right,bottom"/>

XAML Values

uniform

A value measured by logical pixels that specifies a uniform Thickness. The uniform value is applied to all four Thickness properties (Left, Top, Right, Bottom).

left&right

A value measured by logical pixels that specifies the Left and Right of a symmetrical Thickness.

top&bottom

A value measured by logical pixels that specifies the Top and Bottom of a symmetrical Thickness.

left top right bottom

Values measured by logical pixels that specify the four possible dimension properties of a Thickness structure (Left, Top, Right, Bottom).

  • In the XAML syntaxes shown, you can use a space rather than a comma as the delimiter between values.

  • See Remarks for value type, value bounds, and edge-case considerations that affect both code and XAML usages of Padding.

Property Value

Type: System.Windows.Thickness
The dimensions of the space between the border and its child as a Thickness value. The Thickness values are in logical pixels.

Dependency property identifier field: PaddingProperty

The HorizontalAlignment and VerticalAlignment properties of the Border element are Stretch by default. This causes the border to stretch to the edges of the parent container and can look the same as setting a large Padding value. Setting HorizontalAlignment and VerticalAlignment to Center causes the Border to wrap its child element which shows the proper Padding value.

You can set a uniform padding for all sides of the border or set a specific value for each side. For details, see Thickness.

Negative values for Thickness values are technically permitted, but should be used with caution when setting the Padding property. Negative values cause the border to be drawn inside rather than outside the child object, but they could be used in this way for deliberate effect.

Nonintegral values of a Thickness for Padding are technically permitted, but should generally be avoided. Nonintegral values introduce subpixel rendering, which can possibly result in antialiasing artifacts.

The following example shows how to set the Padding property for a Border.


<Grid ShowGridLines="True" x:Name="LayoutRoot" Background="Transparent">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Border Grid.Row="0" Grid.Column="0" Padding="10" BorderThickness="50" HorizontalAlignment="Center" VerticalAlignment="Center"  BorderBrush="Blue">
        <Rectangle Height="100" Width="150" Fill="Red" /> 
    </Border>
</Grid>


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft