Struct GridLength
Specifies the size of a Grid row or column.
public readonly record struct GridLength : IParsable<GridLength>, IEquatable<GridLength>
- Implements
- Inherited Members
- Extension Methods
Constructors
GridLength(float, GridUnitType)
Specifies the size of a Grid row or column.
public GridLength(float Value, GridUnitType UnitType)
Parameters
ValuefloatThe size, interpreted per
UnitType- pixels for Pixel, a proportional weight for Star, or ignored for Auto.UnitTypeGridUnitTypeHow
Valueshould be interpreted.
Properties
Auto
Gets a GridLength that sizes to the largest desired size among the track's children.
public static GridLength Auto { get; }
Property Value
Star
Gets a GridLength that takes an equal (weight 1) proportional share of remaining space.
public static GridLength Star { get; }
Property Value
UnitType
How Value should be interpreted.
public GridUnitType UnitType { get; init; }
Property Value
Value
The size, interpreted per UnitType - pixels for Pixel, a
proportional weight for Star, or ignored for Auto.
public float Value { get; init; }
Property Value
Methods
Parse(string, IFormatProvider?)
Parses a track size written the way markup writes it.
public static GridLength Parse(string s, IFormatProvider? provider)
Parameters
sstringAuto,, a star weight such as2, or a pixel count such as24. Case-insensitive forAuto.providerIFormatProviderThe format provider used for the numeric part.
Returns
- GridLength
The parsed track size.
Remarks
Implementing IParsable<TSelf> is what lets
TypeConversionManager - and therefore markup - turn
Width="*" into a value with no bespoke converter registration.
Exceptions
- FormatException
sis none of the accepted forms.
StarWeighted(float)
Creates a GridLength that takes a proportional share of remaining space, weighted relative to other Star tracks.
public static GridLength StarWeighted(float weight)
Parameters
weightfloatThe proportional weight.
Returns
- GridLength
A Star GridLength with the given weight.
TryParse(string?, IFormatProvider?, out GridLength)
Attempts to parse a track size written the way markup writes it.
public static bool TryParse(string? s, IFormatProvider? provider, out GridLength result)
Parameters
sstringAuto,, a star weight such as2, or a pixel count such as24.providerIFormatProviderThe format provider used for the numeric part.
resultGridLengthThe parsed track size, or the default value when parsing failed.
Returns
Operators
implicit operator GridLength(float)
Implicitly converts a pixel size to a fixed GridLength.
public static implicit operator GridLength(float pixels)
Parameters
pixelsfloatThe fixed size, in pixels.