-
I have created a demo project here: https://github.com/MartyIX/VisualElementXY202311 (.NET 8 RC2) It contains the method (added in the commit): private (double x, double y) GetCoordinatesWithinWindow(VisualElement element)
{
double x = 0;
double y = 0;
VisualElement? workingElement = element;
while (workingElement is VisualElement visualElement)
{
x += visualElement.X;
y += visualElement.Y;
workingElement = workingElement.Parent as VisualElement;
}
return (x, y);
} And I wonder whether this compution is fundamentally valid or not. I mean whether the computation gives what I claim it to be - ie coordinates of the element relative to the enclosing window. Does anybody know? btw: We experimented with this code and for an element we expected the X coordinate to be equal to |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@mattleibow @hartez Would you possibly know please? |
Beta Was this translation helpful? Give feedback.
This looks valid to me. The slight difference in your actual and expected values might be coming from rounding errors and conversions between native screen locations and the virtual locations (due to differing screen densities).