GridLength Structure
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Represents the length of elements that explicitly support Star unit types.
Namespace: System.Windows
Assembly: System.Windows (in System.Windows.dll)
Syntax
'Declaration
Public Structure GridLength
public struct GridLength
<GridLength ...>doubleValue</GridLength>
- or -
<GridLength ...>starSizing</GridLength>
- or -
<GridLength ...>Auto</GridLength>
<object property="doubleValue"/>
- or -
<object property="starSizing"/>
-or-
<object property="Auto"/>
XAML Values
doubleValue
The row's height, or column's width, expressed as a floating-point value for a pixel count. Typically this is specified as an integer, although interpolation of floating-point values is supported by grid layout.starSizing
A string that includes the * character. Sizes rows or columns to take the remaining available space in a Grid. See the "Star Sizing" section in Remarks,Auto
The column's width, or the row's height, described by the literal Auto. For more information about Auto sizing, see Grid.
The GridLength type exposes the following members.
Constructors
Name | Description | |
---|---|---|
GridLength(Double) | Initializes a new instance of the GridLength structure using the specified absolute value in pixels. | |
GridLength(Double, GridUnitType) | Initializes a new instance of the GridLength structure and specifies what kind of value it holds. |
Top
Properties
Name | Description | |
---|---|---|
Auto | Gets an instance of GridLength that holds a value whose size is determined by the size properties of the content object. | |
GridUnitType | Gets the associated GridUnitType for the GridLength. | |
IsAbsolute | Gets a value that indicates whether the GridLength holds a value that is expressed in pixels. | |
IsAuto | Gets a value that indicates whether the GridLength holds a value whose size is determined by the size properties of the content object. | |
IsStar | Gets a value that indicates whether the GridLength holds a value that is expressed as a weighted proportion of available space. | |
Value | Gets a Double that represents the value of the GridLength. |
Top
Methods
Name | Description | |
---|---|---|
Equals(GridLength) | Determines whether the specified GridLength is equal to the current GridLength. | |
Equals(Object) | Determines whether the specified object is equal to the current GridLength instance. (Overrides ValueType.Equals(Object).) | |
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.) | |
GetHashCode | Gets a hash code for the GridLength. (Overrides ValueType.GetHashCode().) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
ToString | Returns a String representation of the GridLength. (Overrides ValueType.ToString().) |
Top
Operators
Name | Description | |
---|---|---|
Equality | Compares two GridLength structures for equality. | |
Inequality | Compares two GridLength structures to determine if they are not equal. |
Top
Remarks
Elements such as ColumnDefinition and RowDefinition use this type to describe width and height in order to support variable distribution of available space.
If you specify a GridLength for use as a resource, use the object element usage and set the GridLength value using initialization text.
Star Sizing
Star sizing is a convention whereby any GridLength measurement that includes an asterisk (*) in its XAML-declared value uses any remaining space for rows or columns. * can be preceded with a number value that specifies a weighted factor versus other possible star sizings (for example, 3*). If all GridLength values that declare rows or columns use star sizing, the space is divided equally, but with any number weights factored in.
The following table provides some examples of star sizing results. For these examples, assume that the parent Grid has a fixed Width of 600, and that these values apply to the Width of three ColumnDefinition elements.
Column 0 |
Column 1 |
Column 2 |
Result |
---|---|---|---|
100 |
100 |
* |
100,100,400 |
100 |
* |
* |
100,250,250 |
* |
2* |
3* |
100,200,300 |
100 |
* |
4* |
100,100,400 |
In code, a star sizing is equivalent to a GridLength where GridLength.IsStar is true, GridLength.GridUnitType is Star, and GridLength.Value is the weighted factor applied, if any (GridLength.Value is 1 for *).
Noninteger numeric factors are allowed, for example .5*.
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.