Partager via


Thickness Structure

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Describes the thickness of a frame around a rectangle. Four Double values describe the Left, Top, Right, and Bottom sides of the rectangle, respectively.

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

Syntax

'Declaration
Public Structure Thickness
public struct Thickness
<Thickness ...>uniform</Thickness>
- or -
<Thickness ...>left&right,top&bottom</Thickness>
- or -
<Thickness ...>left,top,right,bottom</Thickness>
<object property="uniform"/>
- or -
<object property="left&right,top&bottom"/>
- or -
<object property="left,top,right,bottom" ... />

XAML Values

  • uniform
    A numeric value that specifies a uniform Thickness. The uniform value is applied to all four Thickness properties (Left, Top, Right, Bottom).

  • left&right
    A numeric value that specifies the Left and Right of a symmetrical Thickness.

  • top&bottom
    A numeric value that specifies the Top and Bottom of a symmetrical Thickness.

  • left, right ,top, bottom
    Numeric values that specify the four possible dimension properties of a Thickness structure (Left, Top, Right, Bottom).

In the XAML syntaxes shown above, you can also use one or more spaces as the delimiter between values, rather than a comma.

See Remarks for additional information on value constraints that apply both to XAML and to code.

The Thickness type exposes the following members.

Constructors

  Name Description
Public methodSupported by Silverlight for Windows Phone Thickness(Double) Initializes a Thickness structure that has the specified uniform length on each side.
Public methodSupported by Silverlight for Windows Phone Thickness(Double, Double, Double, Double) Initializes a Thickness structure that has specific lengths (supplied as a Double) applied to each side of the rectangle.

Top

Properties

  Name Description
Public propertySupported by Silverlight for Windows Phone Bottom Gets or sets the width, in pixels, of the lower side of the bounding rectangle.
Public propertySupported by Silverlight for Windows Phone Left Gets or sets the width, in pixels, of the left side of the bounding rectangle.
Public propertySupported by Silverlight for Windows Phone Right Gets or sets the width, in pixels, of the right side of the bounding rectangle.
Public propertySupported by Silverlight for Windows Phone Top Gets or sets the width, in pixels, of the upper side of the bounding rectangle.

Top

Methods

  Name Description
Public methodSupported by Silverlight for Windows Phone Equals(Object) Compares this Thickness structure to another Object for equality. (Overrides ValueType.Equals(Object).)
Public methodSupported by Silverlight for Windows Phone Equals(Thickness) Compares this Thickness structure to another Thickness structure for equality.
Protected methodSupported by Silverlight for Windows Phone Finalize Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone GetHashCode Returns the hash code of the structure. (Overrides ValueType.GetHashCode().)
Public methodSupported by Silverlight for Windows Phone GetType Gets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows Phone MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone ToString Returns the string representation of the Thickness structure. (Overrides ValueType.ToString().)

Top

Operators

  Name Description
Public operatorStatic memberSupported by Silverlight for Windows Phone Equality Compares the value of two Thickness structures for equality.
Public operatorStatic memberSupported by Silverlight for Windows Phone Inequality Compares two Thickness structures for inequality.

Top

Remarks

Thickness is primarily used to describe the Margin of a FrameworkElement, the BorderThickness of a Border, or the Padding of a Control.

All property values of a Thickness must be greater than 0. The programmatic upper limit for values is not PositiveInfinity, it is a lower number (approximately 1,000,000) that is enforced by the Silverlight native code.

Although the type of the property values of a Thickness is Double, you generally should use integer values. For more information, see Layout Rounding.

In XAML, you can specify Thickness values in several ways. If you specify four Double values, these represent the Left, Top, Right and Bottom sides, respectively, of the bounding rectangle. if you specify two values, these represent the Left, Top values, and also applies the same values to Right and Bottom such that the resulting Thickness is isometric horizontally and isometric vertically. You can also supply a single value, which applies a uniform value to all four sides of the bounding rectangle. Note that although a format that specifies three values does not cause a parser error, the first value is used for both the left and right value, and any third value is ignored. This is why a three-value usage is not shown (it is really the two-value form being interpreted.) Values assigned from code do not have any behavior that can extrapolate values. If you set the value for Left, you do not automatically establish the same value for Right. All Thickness properties must be set discretely in code, although the Thickness(Double) constructor provides a way to set an initial uniform value.

Properties of Thickness do not support an attribute syntax in XAML for Silverlight. In XAML you should always specify Thickness -type properties through one of the following usages:

  • The XAML attribute usage, which infers properties that use the Thickness type and uses a type converter to process the attribute string into the specific values for the Thickness.

  • A property element usage, containing a Thickness object element. For that object element, set the Thickness properties using initialization text, as shown in the XAML Object Element Usage.

If you specify a Thickness for use as a resource, use the object element usage and set the Thickness properties using initialization text.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference