Sunday, 30 January 2011

How to calculate coordinates of a control in WPF

If you have a control nested in another control and you have to calculate their coordinates, you can achieve it using TranslatePoint(..,..) method e.g. [your control].TranslatePoint(new Point(0, 0), [parent control]); If you need to retrieve a control coordinates to make it visible on the screen you can consider BringIntoView() method. The only problem with previously mentioned method is lack of consistency but on the other hand you do not have to perform any additional calculations.

Please have a look at the following example if you want to see TranslatePoint and BringIntoView methods in action:

No comments:

Post a Comment