Are the WPF Window position properties Left, Top, Height and Width ever actually Doubles?
The position properties Left, Top, Height 开发者_运维技巧and Width of a WPF Window are Doubles. However when interacting with windows messages like WM_MOVING and WM_MOVE, one must cast the double to an integral type.
This seemed okay to me since all the Windows Notifications seem to use integral types in all their positions arguments and I imagine that these messages are closely tied to the WPF postion properties.
So the question is, am I correct in this assumption or can the windows notifications actually be doubles and eventually there's going to be some weird side-effect to this?
In WPF windows, these properties actually map to the Window's position, which, as you noted (in Windows) will map to an integer value eventually.
However, they're defined as doubles, which is nice as they map cleanly to (and inherit from) other FrameworkElement properties, ie: FrameworkElement.Width. Elements within a window do take advantage of double precision, as they're designed to be resolution independent and allow arbitrary scaling via a Transform, etc.
To make these integers, the framework would have to make Window not be a FrameworkElement, or define separate properties for these, ignoring the FrameworkElement's properties. Either option would cause confusion and be worse than leaving these double values. Also, realize that it's possible for an implementation in the future to use sub-pixel positioning - though the Windows API does not support this now, it's theoretically possible (unlikely though) it could in the future.
When it comes down to the windows messages and window positions, the numbers must be converted to integers, no doubt.
But before the real output the item coordinates can be shifted by some small amount (say, less then 0.5 pixels), or the containing item can be stretched by some non-integer coefficient. Another application of the floating-point coordinates is the case when some space is divided into equally-sized columns: you cannot divide 100 pixels by 3 without going to the floating point (well, with floating point there is still some error, but it can be neglected).
So, all the internal coordinates and operations over them are calculated in doubles, and the conversion to ints happens only when it comes to the real screen.
精彩评论