public value class Thickness
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.UI.Xaml.WinUIContract, 65536)] /// [Windows.Foundation.Metadata.WebHostHidden] struct Thickness
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.UI.Xaml.WinUIContract), 65536)] [Windows.Foundation.Metadata.WebHostHidden] public struct Thickness
Public Structure Thickness
<Thickness ...>uniform</Thickness> - or - <Thickness ...>left&right,top&bottom</Thickness> - or - <Thickness ...>left,top,right,bottom</Thickness> - or - <object property="uniform"/> - or - <object property="left&right,top&bottom"/> - or - <object property="left,top,right,bottom" ... />
Thickness values are generally used to set properties that affect the layout of the object where the property is set. Properties that use a Thickness value include:
- Border.BorderThickness and Control.BorderThickness
- Other Margin and Padding properties on classes that are not a Control, for example RichTextBlock.Padding
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.
Values assigned from code do not have any behavior that can extrapolate values. If you set the value for a Left property or field, you do not automatically establish the same value for Right. All Thickness properties must be set discretely in code. You can use the Thickness(Double) or Thickness(Double,Double,Double,Double) constructors rather than assigning values to properties.
Although the type of the data values of a Thickness is Double, you typically specify integer values.
Notes on XAML syntax
A string that specifies three values does not cause a parser error, but only the first two values are interpreted, and any third value is ignored.
Although you can specify a Thickness as an object element, you cannot specify the individual values such as Top as attributes of that object element. The XAML parser does not support setting XAML attribute values for this structure. Instead, you must specify the values as initialization text within the Thickness. Using the object element syntax for a Thickness is useful if you want to declare a keyed resource that can be used by multiple Control instances for their Padding. For more info on XAML initialization text, see XAML syntax guide.
You can use a space rather than a comma as the delimiter between values.
Projection and members of Thickness
If you are using a Microsoft .NET language (C# or Microsoft Visual Basic), or Visual C++ component extensions (C++/CX), then Thickness has non-data members available, and its data members are exposed as read-write properties, not fields. See Thickness in the .NET API Browser.
If you are programming with C++/WinRT or the Windows Runtime C++ Template Library (WRL), then only the data member fields exist as members of Thickness, and you cannot use the utility methods or properties of the .NET projection. C++ code can access similar utility methods that exist on the ThicknessHelper class.
This table shows the equivalent methods available in .NET and C++.
|.NET (Thickness)||C++ (@"Microsoft.UI.Xaml.ThicknessHelper?text=ThicknessHelper" )|
|Thickness(Double, Double, Double, Double)||FromLengths(Double, Double, Double, Double)|
The bottom edge measure of the Thickness.
The left side measure of the Thickness.
The right side measure of the Thickness.
The top edge measure of the Thickness.