This is the second post in a series where I will be walking through some of the new features in Silverlight 3. I enjoyed reading Tim Sneath’s blog post, http://visitmix.com/Opinions/Whats-New-in-Silverlight-3 but as I read the post I kept saying cool, but how do I do it. So in these posts I will try to answer the “how do I” questions around the new features.
Let’s get started.
Perspective 3d gives you the ability to "simulate" 3D using 2D objects.
In order to create Silverlight 3 projects you will need to install Visual Studio 2008, and the Silverlight 3 SDK and tools. Create a Silverlight C# project called Perspective3D and accept the defaults which will create 2 projects in the solution.
In this example you will use an image to transform. Add an image to the ClientBin folder of the web project. I have added an image of my latest book.
Start with a basic image element.
<Grid x:Name="LayoutRoot" Background="White">
When you run the project (F5) you will see the results below. I have cut out just the image to save space. Below is what the original image looks like before a perspective is added.
To rotate the image along the X axis you need to Projection and then add a PlaneProjection setting the RotationX attribute to the degree you want to rotate the image.
You can set the X, Y and Z rotation. This table shows examples of the various perspectives.
These attributes can be used together to create realistic 3D transforms of your elements.
You can also change the center of rotation by setting the CenterOfRotationX (Y or Z) attributes. This is set as a value between 0.0 and 1.0. By default the X and Y center is 0.5 and the Z center is 0.0. To rotate from the top of the image you set the CenterOfRotationX = 0.0.