<Grid Background="Black" Width="640" Height="480">
<Image Source="Waterfall.jpg" Width="320" Height="240">
</Image>
</Grid>
Submitted by Umesh Patel (March 18, 2009)
Perspective Transforms in Silverlight 3 is the next step towards developing 3D Silverlight applications. In previous versions of Silverlight, transforms were processed in the X and Y axis using the UIElement's RenderTransform property. Silverlight 3 uses the PlaneProjection class to render 3D-like effects. All elements, that derive from UIElement, have the Projection property that allows the element to simulate transformation in a 3D space.
In this tutorial, we will show you how to use the Perspective Transforms for your applications.
<Grid Background="Black" Width="640" Height="480">
<Image Source="Waterfall.jpg" Width="320" Height="240">
</Image>
</Grid>
The 3D space in Silverlight has the X axis in the horizontal direction, Y axis in the vertical direction, and Z axis representing the depth. Translating the objects match the direction of the axis. If you want to object on the left side of the screen, you will move in the negative direction of the X axis. The same goes if you want the object to move to the upper side of the screen in regards to the Y axis. Rotation works differently because the rotation is performed along the axis. If you want to rotate in the X-axis, which is a horizontal axis, the object will actually rotate up and down.
The PlaneProjection class has the following translation properties:
The class also has the following rotation properties:
<Image Source="Waterfall.jpg" Width="320" Height="240">
<Image.Projection>
<PlaneProjection />
</Image.Projection>
</Image>
![]() |
<PlaneProjection RotationX="45" /> |
![]() |
<PlaneProjection RotationY="45" /> |
![]() |
<PlaneProjection RotationZ="45" /> |
![]() |
<PlaneProjection LocalOffsetZ="300" /> |
![]() |
<PlaneProjection LocalOffsetZ="-300" /> |
![]() |
<PlaneProjection RotationX="60" RotationY="60" /> |
![]() |
<PlaneProjection RotationX="-60" RotationZ="60" GlobalOffsetZ="100" /> |
Layout controls also derive from the UIElement and can take advantage of the perspective transformations. This allows for multiple controls to be transformed at the same time.
<StackPanel>
<StackPanel.Projection>
<PlaneProjection RotationX="-60" />
</StackPanel.Projection>
<Image Source="Waterfall.jpg" Width="320" Height="240" />
<TextBlock Text="Sample Image" Foreground="White" FontSize="32" HorizontalAlignment="Center" />
</StackPanel>
<Storyboard x:Key="RotateX" Storyboard.TargetName="projection" Storyboard.TargetProperty="RotationX">
<DoubleAnimation From="0" To="360" RepeatBehavior="Forever" />
</Storyboard>
(this.Resources["RotateX"] as Storyboard).Begin();
Perspective Transformations opens the doors for a wide variety of 3D-like web applications. In its current state, the PlaneProjection class can perform traditional translation and rotation on the respected object. These transformations can be further parented to have advanced perspective transformations.