HOW TO GET XY COORDINATES OF A CONTROL IN WPF?

ben reitman

Total Post:96

Points:676
Posted by  ben reitman
WPF
 4885  View(s)
Ratings:
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.
  1. Pravesh Singh

    Post:412

    Points:2888
    Re: How to get XY coordinates of a control in WPF?

    Hi Ben,

    You can try this :

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

         Point relativePoint = myVisual.TransformToAncestor(parent)

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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!