Skip to main content

Microsoft Silverlight

Answered Question how to obtain the rotation angle of a textblock in managed codeRSS Feed

(0)

hhuilil2001@yahoo.com
hhuilil2...

Member

Member

20 points

11 Posts

how to obtain the rotation angle of a textblock in managed code

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!

 

 

Lisa Li
Web Developer

robhouweling
robhouwe...

Contributor

Contributor

3158 points

540 Posts

Silverlight MVP

Re: how to obtain the rotation angle of a textblock in managed code

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



My blog

Skyrunner
Skyrunner

Contributor

Contributor

2489 points

485 Posts

Silverlight MVP

Re: how to obtain the rotation angle of a textblock in managed code

How is your XAML for the textblock and the transform ?

Skyrunner
Skyrunner

Contributor

Contributor

2489 points

485 Posts

Silverlight MVP

Re: how to obtain the rotation angle of a textblock in managed code

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

hhuilil2001@yahoo.com
hhuilil2...

Member

Member

20 points

11 Posts

Re: how to obtain the rotation angle of a textblock in managed code

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.

Lisa Li
Web Developer

hhuilil2001@yahoo.com
hhuilil2...

Member

Member

20 points

11 Posts

Answered Question

Re: Re: how to obtain the rotation angle of a textblock in managed code

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.

Lisa Li
Web Developer
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities