O'Reilly logo

Beginning Windows® Phone 7 Application Development: Building Windows® Phone Applications Using Silverlight® and XNA® by Robert Fonseca-Ensor, Karli Watson, Nick Lecrenski

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

APPLYING TRANSFORMS

At this point, you should have a good understanding of the various shapes, colors, and brushes you can use in Windows Phone 7 applications. Next you will see how to make use of various transform effects like rotation, scaling, skewing, and translation.

The RotateTransform Object

You can rotate just about any Silverlight object without having to create complicated rotation algorithms. Instead, Silverlight provides the RotateTransform object, which you can easily apply to various controls and shapes to rotate them a specified number of degrees.

You use the RotateTransform object in XAML as follows:

<TextBlock x:Name=“RotatedText”Margin=“50”Text=“This text has been rotated”>
     <TextBlock.RenderTransform>
          <RotateTransform Angle=“45”/>
     </TextBlock.RenderTransform>
</TextBlock>

This seems simple enough. Basically, in this example, you rotate a TextBlock object 45 degrees by adding a RotateTransform object with the Angle property set to the RenderTransform property of the TextBlock control. To better understand how this works, first take a look at the RenderTransform property of the TextBlock object. All Silverlight controls contain an attached property called RenderTransform that enables you to specify a type of transform to apply during the rendering of the object. In this case, you add a simple rotation to the text. You can't ask for an easier way to rotate an object than this. Figure 3-15 shows the rotation in action.

FIGURE 3-15: A RotateTransform object.

Adding ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required