Skip to main content
Home Forums Silverlight Programming Programming with .NET - General how to obtain the rotation angle of a textblock in managed code
5 replies. Latest Post by hhuilil2001@yahoo.com on September 5, 2008.
(0)
hhuilil2...
Member
20 points
11 Posts
09-05-2008 10:10 AM |
This is for Silverlight 2 Beta 2.
I am trying to obtain the rotation angle of a textblock in managed code. I was trying to use the following code:
((RotateTransform)(currentText.RenderTransform)).Angle.
But I got an error message saying "can not cast MatrixTransform to RotateTransform". Is there anyone who knows how to get the angle of the rotation transform for a textblock?
Thanks very much!
robhouwe...
Contributor
3158 points
540 Posts
09-05-2008 10:15 AM |
RenderTransform can contain multiple transforms. You will have to check if it is a TransformGroup or a single transform.
Check out this post for an example:
http://silverlight.net/forums/t/23330.aspx
(If this has answered your question, please click on mark as answer on this post)Cheers!Rob Houweling
Skyrunner
2489 points
485 Posts
09-05-2008 10:16 AM |
How is your XAML for the textblock and the transform ?
09-05-2008 10:26 AM |
robhouweling:RenderTransform can contain multiple transforms. You will have to check if it is a TransformGroup or a single transform. Check out this post for an example: http://silverlight.net/forums/t/23330.aspx
If its a MatrixTransform its not a TransformGroup.
Take a look here.
http://silverlight.net/forums/t/20352.aspx
09-05-2008 12:17 PM |
The following is the way the rotationtransform is originally added to the textblock, it is not declared in a xaml file, it is in managed code:
RotateTransform rt = new RotateTransform();
rt.Angle = SliderTextRotation.Value; currentText.RenderTransform = rt;
So what I need is to retreive the angle value later from the textblock. It seemed that it is trickier than I thought.
09-05-2008 12:30 PM |
It turned out that the following code worked:
var renderTransform = currentText.RenderTransform;
if (renderTransform is RotateTransform) { RotateTransform rotateTransform = (RotateTransform)renderTransform; SliderTextRotation.Value = rotateTransform.Angle; }
The casting did not work, but the above code worked. The error message is misleading.
Thanks to your guys.