Silverlight Projections in Blend

   Posted by: Andrew Troelsen

The Silverlight API provides some support for manipulation of 3D data, however it does not currently offer a full-blown 3D framework (as WPF does). Rather, Silverlight opts for a more light weight "3D perspective framework".

Specifically, rather than working with Viewport3D elements, and the assorted camera and lightening objects, any Silverlight which derives from the UIElement base class can change it?s X, Y and Z positioning via the Projection property. This property may be set to a PlaneProjection object, which is a very lightweight version of Viewport3D. In its simplest form, the PlaneProjection object can be configured with RotationX, RotationY and RotationZ properties. It is also possible to control the center point of the rotation (via CenterOfRotationX, CenterOfRotationY and CenterOfRotationZ properties) as well as global and local offsets.

As you would hope, the Blend IDE provides an editor in the Properties panel which will fully configure a PlaneProjection object and connect it to a UIElement. Assume you have configured an Image control, and wish to map the data into a 3D plane.

If you select the Image control on the artboard, you will see that the Transform section of the Properties panel supports a Projection sub-section. This area can be used to set the Projection property of any selected item on the artboard.

Figure 2-60

Like other range-centric controls of the Properties panel, you can use your mouse to adjust the values for the X, Y and Z projection settings (just click and hold on a range control and move your mouse). Again, rather than seeing a Viewport3D, you will see XAML such as the following:

Code Snippet
  1. <Image x:Name="imgCoCoLoCo" Margin="162,18,162,185"
  2. Source="/CoCoLoCo.png" Stretch="Fill">
  3. ????<Image.Projection>
  4. ????????<PlaneProjection RotationX="46"
  5. ??????????????? RotationY="12" RotationZ="-29"/>
  6. ????</Image.Projection>
  7. </Image>

Of course, you can also drive the project via code. Assume you had three Slider controls which allow you to change the X, Y and Z rotations. Also assume each ValueChanged event handler captures the new thumb location, and stores the value in some fitting fields. Each hander could call a helper function such as the following:

Code Snippet
  1. private void ChangeCamera()
  2. {
  3. ????PlaneProjection pp = new PlaneProjection();
  4. ????pp.RotationX = xVal;
  5. ????pp.RotationY = yVal;
  6. ????pp.RotationZ = zVal;
  7. ????????????
  8. ????if(imgCoCoLoCo != null)
  9. ????????this.imgCoCoLoCo.Projection = pp;????????????
  10. }

When you run the project, you can then view the results of mapping this 2D image onto a 3D plane.  Simple, yes?

image


Comments (0)

Be the first one to comment on this post!

Add a Comment

*

*

Loading

Find Us
Contact Us 651-288-7000 1-800-866-9884
Home | Training | Curriculum | Course Finder | Schedule | Enroll | Twin Cities Java User Group | Consulting | Foundation | Jobs | About Us | Our Story | Press Room | Instructors | President | Map & Directions | Sitemap

Java Training | JSF / Struts / Spring / Hibernate Training | Java Power Tools Training | .NET 4.0 & Visual Studio 2010 Training | Microsoft Web Development Training | Prism / MVVM / MEF Training | .NET 3.5 and Visual Studio 2008 Training | .NET 2.0 and Visual Studio 2003 Training | Cloud Computing Training | Ajax / Web Services / XML Training | Groovy and Grails Training | SQL Server 2012 Training | SQL Server 2008 Training | SQL Server 2005 Training | Mobile Development Training | SharePoint 2010 Training | SharePoint 2007 Training | Agile, Process, Analysis & Design Training | Arch/Design Patterns Training | Microsoft Official Curriculum Training | Web Development Training | Ruby Training | Rational Application Developer (RAD) Training | WebSphere Application Server Training | WebSphere Portal Training | WebLogic Training | Boot Camp Training | Project Management Training | C / C++ Training | Metro / WinRT / Windows 8 Development Training | Retired

Intertech delivers training on-site and virtually serving cities including Phoenix, AZ | San Francisco, CA | Los Angeles, CA | San Diego, CA | San Jose, CA | Washington, DC | Chicago, IL | Orlando, FL | Boston, MA | Duluth, MN | Minneapolis St. Paul, MN | Rochester, MN | Raleigh-Durham, NC | New York, NY | Philadelphia, PA | Austin, TX | Dallas, TX | Houston, TX | Seattle, WA.