Reputation: 5480
Can anyone please inform me how I can get the location of a control? Apparently controlName.Margin.Top
doesn't work for me. When I put a break-point, I get 0.0 for the Left value when obviously it's not, the control is half way in the screen.
Upvotes: 1
Views: 443
Reputation: 1402
It's something like
Point position = child.TransformToVisual(ancestor).Transform(new Point(0, 0));
where ancestor is the LayoutRoot or the Page and child is the Control in question.
EDIT: I just read your comment "I want to know what the position of the Control is on my Canvas". ancestor can of course be the direct parent as well.
However in this very case (where the direct parent is a Canvas) the following might be better: var top = myCanvas.GetTop(child);
Upvotes: 4