Repository navigation
Description
Current behavior
GridLengthHelper.FromPixels(double) and GridLengthHelper.FromValueAndType(double, GridUnitType) narrow the argument to float before building the GridLength, even though GridLength.Value is a double:
public static GridLength FromPixels(double pixels) => new GridLength((float)pixels, GridUnitType.Pixel);
public static GridLength FromValueAndType(double value, GridUnitType type) => new GridLength((float)value, type);So precision is lost:
var gl = GridLengthHelper.FromPixels(0.1);
Console.WriteLine(gl.Value == 0.1); // False on Uno (0.10000000149011612), True on WinUI
Console.WriteLine(GridLengthHelper.FromPixels(123456.789).Value); // 123456.7890625 on UnoExpected behavior
The helper keeps the double it was given, like WinUI. WinUI's GridLengthFactory::FromValueAndType takes DOUBLE and stores it as-is (pReturnValue->Value = (type == Auto) ? 1.0 : value;). FromPixels just forwards to it.
Source: GridLength_Partial.cpp (WinUI C++ source inspection, not a runtime repro).
How to reproduce it
- Create any Uno app (or runtime test).
- Run:
var a = GridLengthHelper.FromPixels(0.1); var b = GridLengthHelper.FromValueAndType(123456.789, GridUnitType.Pixel); System.Diagnostics.Debug.WriteLine($"{a.Value == 0.1} {b.Value == 123456.789}");
- Uno prints
False False; WinUI printsTrue True.
Confirmed by code inspection on master (the (float) casts are plain C# narrowing, so the result follows directly from the language rules).
Workaround
new GridLength(value, GridUnitType.Pixel) keeps double precision.
Works on UWP/WinUI
Yes.
Environment
Other
NuGet package version
master @ cc48541
Affected platforms
Other (all heads; shared code)
IDE
No response
Relevant plugins
No response
Anything else we need to know?
Root cause: GridLengthHelper.cs (lines 12-14). Suggested fix: drop the (float) casts (and use 1.0 instead of 1.0f for Auto/OneStar, harmless but consistent).
Practical impact: code that writes GridLengthHelper.FromPixels(x) and later compares column.Width.Value against x (for example to skip redundant writes) can miss on large or fractional values.
Invalid input (NaN, infinity, negative, unknown unit) already throws, because the GridLength constructor validates it, so only the precision loss is a divergence.
Activity
brunoapolinariodev commentedon Oct 15, 2026
Hi! I opened a PR for this: #25511
It removes the (float) casts in GridLengthHelper.FromPixels and FromValueAndType so the double value is kept, and adds unit tests covering Pixel and Star.
fix: Keep double precision in GridLengthHelper