Translating Coordinates In Silverlight 2

by Aaron D-H 25. February 2009 19:11

When you are doing complex things to objects in Silverlight like aninmation of scale and rotation it is sometimes neccesary to be able to translate a point from the object that has been rotated and scaled into it’s parents coordinate system.  Luckly the Silverlight 2 dev team has a solution. 

The correct way to do this in Silverlight 2 is to use the TransformToVisual method as follows:

   
Point pointInClientSpace = new Point(someClientX, someClientY);
GeneralTransform transformFromClientToParent = clientControl.TransformToVisual(parentControl);
Point pointInParentSpace = transformFromClientToParent.Transform( pointInClientSpace );
The msdn info on this function can be found here: TransformToVisual

Tags:

Software Engineering | .NET | C# | Silverlight

Comments


September 3. 2009 01:49
Olivier
Cool but there is a mistake in your code (last line will not compile you're using a variable as a method call). I think ".Transform(xxx)" is missing.


September 3. 2009 09:52
aarondh
Your very right... Thanks for catching the typo.

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



About the Author

I'd like to introduce myself to you... My name is Aaron Daisley-Harrison.  I have worked in the software engineering field for a number of years, and as an  Application Architect have created solutions for many industry verticals; worked with both Sun Microsystem and Microsoft technologies; Developed SQL database engines as well as full text search systems; and Knowledge management systems.   I am currently doing contract work out of the Pacific North West and have lately been focusing on Microsoft technologies like SharePoint 2007/2010, WCF, Identity Framework, JQuery, Xml and Silverlight.
[more]


 Digg!

 

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2009 Aaron G. Daisley-Harrison - All Rights Reserved.