How to get XY coordinates of a control in WPF?

Total Post:96

Points:676

WPF
 6234  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. 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

Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.