Home > DeveloperSection > Forums > How to get XY coordinates of a control in WPF?
ben reitman
ben reitman

Total Post:96

Posted on    September-23-2013 7:58 AM


 1 Reply(s)
 4798  View(s)
Rate this:

Point relativePoint = myVisual.TransformToAncestor(rootVisual)

                              .Transform(new Point(0, 0));

this code block is very useful but, I use MVVM therefore the code block is useless for me ?

I wanna to get X & Y without using rootVisual.

Thanks & Best Regards.

Pravesh Singh

Total Post:412

Posted on    September-23-2013 8:27 AM

Hi Ben,
You can try this :

var parent = VisualTreeHelper.GetParent(myVisual) as UIElement;

     Point relativePoint = myVisual.TransformToAncestor(parent)

                          .Transform(new Point(0, 0));

Don't want to miss updates? Please click the below button!

Follow MindStick