WPF - Finding Control Location
Recently for a sample application I was building in WPF, I had to find the location of a button control on the window. Playing around with Button.Margin didn't help much since it gave the position with reference to the immediate parent. So if the button was inside a Grid and the grid itself inside say a StackPanel, the values were incorrect.
Searching on the forums, I got some ideas and following is what worked for me
GeneralTransform transform = button1.TransformToAncestor(this);
Point rootPoint = transform.Transform(new Point(0, 0));
button1 is the control for whom I wanted to find the location. The this represents the top level window. The value obtained in rootPoint is the Left and Top cordinates of the button with respect to the top level window. Adding button's height and width will give the complete location details.