BnLength
Namespace: BlazorNative.Components
A layout length: a number of points, or a percentage. There is deliberately no
conversion from string — that absence is what makes Width="12px" a
compile error rather than a value both shells log and ignore.
public readonly record struct BnLength
Inheritance Object → ValueType → BnLength
Implements IEquatable<BnLength>
Attributes IsReadOnlyAttribute
Remarks:
Use it as BnLength? on a parameter, never bare. null means "unset"
and reaches the wire as an absent attribute, which is what makes the shells reset
the style. A bare default(BnLength) is zero points — a real length —
and would silently collapse a node nobody meant to size.
Negative values are representable and are rejected by the shells, not by this type.
They are legal on margin and the insets and illegal elsewhere, which is a
per-property rule this type does not carry.
Properties
Value
The magnitude.
public float Value { get; init; }
Property Value
Unit
Whether Value is points or a percentage.
public BnLengthUnit Unit { get; init; }
Property Value
Constructors
BnLength(Single, BnLengthUnit)
A layout length: a number of points, or a percentage. There is deliberately no
conversion from string — that absence is what makes Width="12px" a
compile error rather than a value both shells log and ignore.
public BnLength(float Value, BnLengthUnit Unit)
Parameters
Value Single
The magnitude.
Unit BnLengthUnit
Whether Value is points or a percentage.
Remarks:
Use it as BnLength? on a parameter, never bare. null means "unset"
and reaches the wire as an absent attribute, which is what makes the shells reset
the style. A bare default(BnLength) is zero points — a real length —
and would silently collapse a node nobody meant to size.
Negative values are representable and are rejected by the shells, not by this type.
They are legal on margin and the insets and illegal elsewhere, which is a
per-property rule this type does not carry.
Methods
Percent(Single)
A length as a percentage of the parent's corresponding dimension.
public static BnLength Percent(float value)
Parameters
value Single
The percentage, without the sign.
Returns
BnLength
A percentage-valued length.
ToStyleValue()
The wire form, INVARIANTLY. The shells parse with a C/Java float parser, so a
Dutch locale must never put "1,5" on the wire.
public string ToStyleValue()
Returns
String
A bare number, or a number with a trailing percent sign.
Operators
implicit operator BnLength(Single)
A length in points.
public static implicit operator BnLength(float points)
Parameters
points Single
The magnitude, in density-independent points.
Returns
implicit operator BnLength(Double)
A length in points, from a double. Required, not a convenience: Razor
compiles Width="12.5" as a double literal, and double to
float is a narrowing conversion, so without this every decimal literal in
markup fails to compile.
public static implicit operator BnLength(double points)
Parameters
points Double
The magnitude, in density-independent points.