I have UIElements (circles/rectangles) inside a canvas. I want to get X/Y for a UIElement relative to its parent (Canvas). But I am not able to get it.
There are some solutions for this. I tried doing this (Find position of Button/UIElement on screen relative to grid Windows Phone)
var transform = button.TransformToVisual(grid);
Point absolutePosition = transform.Transform(new Point(0, 0));
But I am getting 0,0 in absolutePosition. I am able to see the circles properly in the map. But I am not sure why I am getting wrong X/Y.
Here is my actual code.
Canvas.SetLeft(shape, Position.X);
Canvas.SetBottom(shape, Position.Y);
canvas.Children.Add(shape);
var transform = shape.TransformToVisual(canvas);
Point absolutePosition = transform.Transform(new Point(0, 0));
Whatever I pass in transform.Transform
I am getting that in output.