EN
Este conteúdo não está disponível em seu idioma, mas aqui está a versão em inglês.

GridLength structure

Applies to Windows and Windows Phone

Represents a measurement for control logic that explicitly supports Star (*) sizing and Auto sizing.

Syntax


public struct 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 noninteger values is supported by grid layout.

starSizing

A string that includes the * character. A star sizing sizes rows or columns to take the remaining available space in a Grid. The * character can be preceded by a numeric factor that distributes available space in relation to any other star sizings, in other peer row or column definitions. For example, if Column A has star sizing of * and Column B has star sizing of 2*, then Column A receives one-third the available space and Column B receives two-thirds.

Auto

The column's width or the row's height, described by the literal string token "Auto". Auto sizing distributes space based on the size of the content that is within a column or row.

Note  Object element usage in XAML is supported but it's rarely useful, thus it's not shown.

Attributes

[Version(0x06020000)]
[WebHostHidden()]

Members

The GridLength structure has these types of members:

Constructors

The GridLength structure has these constructors.

ConstructorDescription
GridLength(Double) Initializes a new GridLength structure, using the specified absolute value in pixels.
GridLength(Double, GridUnitType) Initializes a new GridLength structure and specifies what kind of value it holds.

 

Fields

The GridLength structure has these fields.

FieldData typeDescription
GridUnitType

GridUnitType

A value of the GridUnitType enumeration that qualifies how Value is interpreted as a measure.

Value

System.Double [.NET] | float64 [C++]

The measure for this GridLength, which is not necessarily a pixel measure.

 

Methods

The GridLength structure has these methods. It also inherits methods from the Object class.

MethodDescription
Equals(Object) [C#, VB]Determines whether the specified object is equal to a GridLength.
GetHashCode [C#, VB]Gets a hash code for this object.
ToString [C#, VB]Converts a GridLength to a String representation.

 

Operators

The GridLength structure has these operators.

OperatorDescription
Equality Compares two GridLength structures for equality.
Inequality Compares two GridLength structures for inequality.

 

Properties

The GridLength structure has these properties.

PropertyAccess typeDescription

Auto

Read-onlyGets an instance of GridLength that holds a value whose size is determined by the size properties of the content object.

GridUnitType

Read-onlyGets the associated GridUnitType for the GridLength.

IsAbsolute

Read-onlyGets a value that indicates whether the GridLength holds a value that represents an absolute measure in pixels.

IsAuto

Read-onlyGets a value that indicates whether the GridLength holds a value whose size is determined by the size properties of the content object where the GridLength applies.

IsStar

Read-onlyGets a value that indicates whether the GridLength holds a value that is expressed as a weighted proportion of available space.

Value

Read-onlyGets a Double that represents the value of the GridLength.

 

Remarks

Types such as ColumnDefinition and RowDefinition use GridLength values for some of their properties (ColumnDefinition.Width and RowDefinition.Height). These property values are used to support variable distribution of available space in layout containers such as Grid (and also derived types of Grid such as VariableSizedWrapGrid). A GridLength can describe one of three modes for sizing: a fixed width, a weighted distribution (star sizing), or an "Auto" sizing mode.

GridLength values are typically declared in XAML attribute syntax. In XAML, the weighted distribution is declared using a "*" symbol, preceded by a number that declares the weighting factor to use for that GridLength. The weighted distribution option is also known as star sizing.

The data values held by a GridLength (Value and GridUnitType) are both read-only. If you want to change the value of a property that takes a GridLength at run time, you'll have to create a new value using one of the constructors and replace the previous value.

Star sizing

Star sizing is a convention whereby a GridLength has a number value that specifies a weighted factor versus other GridLength values. Any GridLength values that use star sizing divide the available space, accounting for the weighting factors, and evaluating after any fixed widths are applied. If none of the star sizings have weighting factors, the height or width is divided equally amongst them. The default weighting factor is 1.

This table provides some examples of star sizing results. For these examples, assume that the parent Grid has a fixed width of 600, and that there are three columns.

Column 0Column 1Column 2Result
100100*100,100,400
100**100,250,250
100*4*100,100,400

 

In code, a star sizing is equivalent to a GridLength where IsStar is true, GridUnitType is Star, and Value is the weighted factor applied.

Noninteger weighting factors are permitted, for example ".5*".

Auto sizing

Auto sizing distributes space evenly based on the size of the content that is within a column or row. The exact logic for auto sizing is implemented by the control or class using the GridLength values. Typically that class is Grid, as it interprets its RowDefinition and ColumnDefinition components.

Notes on XAML syntax

Although you can specify a GridLength as an object element, you cannot specify the individual values such as Value 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 GridLength. For more info on XAML initialization text, see Basic XAML syntax guide.

Projection and members of GridLength

If you are using a Microsoft .NET language (C# or Microsoft Visual Basic), or in Visual C++ component extensions (C++/CX), then GridLength has non-data members available, and its data members are exposed as read-only properties, not fields.

If you are programming with C++ using the Windows Runtime Template Library (WRL), then only the data member fields exist as members of GridLength, and you cannot use the utility methods or properties listed in the members table. WRL code can access similar utility methods that exist on the GridLengthHelper class, for example FromValueAndType.

Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.UI.Xaml
Windows::UI::Xaml [C++]

Metadata

Windows.winmd
Platform.winmd

Assembly

System.Runtime.WindowsRuntime.UI.Xaml.dll

See also

Grid
ColumnDefinition
RowDefinition
ColumnDefinition.Width
RowDefinition.Height
GridUnitType
Quickstart: Defining layouts

 

 

Mostrar:
© 2014 Microsoft