GridLength Structure
TOC
Collapse the table of content
Expand the table of content

GridLength Structure

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

Represents the length of elements that explicitly support Star unit types.

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

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 logical 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.

  NameDescription
Public methodGridLength(Double)Initializes a new instance of the GridLength structure using the specified absolute value in logical pixels.
Public methodGridLength(Double, GridUnitType)Initializes a new instance of the GridLength structure and specifies what kind of value it holds.
Top

  NameDescription
Public propertyStatic memberAutoGets an instance of GridLength that holds a value whose size is determined by the size properties of the content object.
Public propertyGridUnitTypeGets the associated GridUnitType for the GridLength.
Public propertyIsAbsoluteGets a value that indicates whether the GridLength holds a value that is expressed in logical pixels.
Public propertyIsAutoGets a value that indicates whether the GridLength holds a value whose size is determined by the size properties of the content object.
Public propertyIsStarGets a value that indicates whether the GridLength holds a value that is expressed as a weighted proportion of available space.
Public propertyValueGets a Double that represents the value of the GridLength.
Top

  NameDescription
Public methodEquals(GridLength)Determines whether the specified GridLength is equal to the current GridLength.
Public methodEquals(Object)Determines whether the specified object is equal to the current GridLength instance. (Overrides ValueType.Equals(Object).)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeGets a hash code for the GridLength. (Overrides ValueType.GetHashCode().)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a String representation of the GridLength. (Overrides ValueType.ToString().)
Top

  NameDescription
Public operatorStatic memberEqualityCompares two GridLength structures for equality.
Public operatorStatic memberInequalityCompares two GridLength structures to determine if they are not equal.
Top

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 300, and that these values apply to the Width of three ColumnDefinition elements.

Column 0

Column 1

Column 2

Result

50

50

*

50,50,200

50

*

*

50,125,125

*

2*

3*

50,100,150

50

*

4*

50,50,200

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*.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

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

Show:
© 2017 Microsoft