Unlike the Point Structure used in WPF, Point structure in UWP is a Windows Runtime structure that under Windows.Foundation namespace and can be used across .NET, C++ and JavaScript.
If we look at Fields of Point structure, we will find the fields use a data type as following:
Number [JavaScript] | System.Single [.NET] | float32 [C++]
So internally, the value is stored as single-precision 32-bit number. However, while using Microsoft .NET language, Point's data members are exposed as double
properties, not fields.
Ref Projection and members of Point section of Remarks:
If you are using a Microsoft .NET language (C# or Microsoft Visual Basic), or Visual C++ component extensions (C++/CX), then Point has non-data members available, and its data members are exposed as read-write properties, not fields. .NET supports this functionality through the System.Runtime.WindowsRuntime.dll interop assembly that's shipped as part of .NET for Windows Runtime apps.
So while using C# or Visual Basic, we use the Point.Point constructor that accepts two System.Double parameters. For C# or Visual Basic, the data type of Point.X and Point.Y property is also System.Double
.
And what happens in your code is that while initializing, your x
and y
values are first converted to System.Single
and when retrieving property, it converts to System.Double
again like:
Double x = 400.002015366677, y = 300.000014;
Double X = Convert.ToDouble(Convert.ToSingle(x)); //X is 400.00201416015625
Double Y = Convert.ToDouble(Convert.ToSingle(y)); //Y is 300
For Point structure, I'm afraid we can't get the accurate original value. Point is usually used for UI positioning and rendering. In this scenario, it is recommended to use integer values.
X and Y for a Point can be non-integer values. However, this can introduce the possibility of sub-pixel rendering, which can change colors and anti-alias any straight line along the sub-pixel edge. That's how the XAML rendering engine treats sub-pixel boundaries. So for best results, use integer values when declaring coordinates and shapes that are used for UI positioning and rendering.
If you do need double values, I'd suggest you define a new structure and do not use Point.