Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to calculate the position[point] of UIElement on browser. I am considering the zoom factor.
I have following extension method to do it:

C#
public static Point GetPosition(this UIElement element)
       {
           var gt = element.TransformToVisual(Application.Current.RootVisual);
           var position = gt.Transform(new Point(0, 0));
           var zoomFactor = Application.Current.Host.Content.ZoomFactor;   //Adjust to Browser Zooming.
           return new Point(position.X * zoomFactor, position.Y * zoomFactor);
       }


But when I change the browser zoom other than 100% [less or greater], it does not work in expected way.

If I do not consider the zoomfactor while calculating the point of UIElemet, its behavior is expected[for any zoom factor].

But I dont see anywhere mentioned that we have to consider zoomfactor or not.

And one more fact that this piece of code was working with SL 2 OR SL 3.

Any input/fact is appreciated.

Thanks in advance.

-Sumit
Posted
Updated 30-Nov-14 18:19pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900