BlackWaspTM

This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

Windows Presentation Foundation
.NET 4.0+

XAML

The second part of the Windows Presentation Foundation Fundamentals tutorial looks at the Extensible Application Markup Language (XAML), providing some samples of its use. This is the XML-based language that is used to create WPF user interfaces.

Graphics

For our last example we'll look at a completely new XAML document. WPF and XAML allow you to create two-dimensional vector graphics and three-dimensional scenes containing object meshes with materials, lighting and camera positions. The final XAML document displays a three-dimensional, square-based pyramid. Note the mesh, which is created from points in space that are connected using triangles. Note also the positioning and orientation of the camera and spotlight controls.

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
   <Viewport3D>
      <Viewport3D.Camera>
         <PerspectiveCamera LookDirection="40,-5,-20" Position="-50,10,40"
                            UpDirection="0,1,0.2"/>
      </Viewport3D.Camera>
      <ModelVisual3D>
         <ModelVisual3D.Content>
            <Model3DGroup>
               <GeometryModel3D>
                  <GeometryModel3D.Geometry>
                     <MeshGeometry3D Positions="0,0,0 0,0,10 10,0,10 10,0,0 5,10,5"
                                     TriangleIndices="0,2,1 3,2,0 0,1,4 1,2,4 2,3,4 3,0,4"/>
                  </GeometryModel3D.Geometry>
                  <GeometryModel3D.Material>
                     <DiffuseMaterial Brush="Orange"/>
                  </GeometryModel3D.Material>
               </GeometryModel3D>
               <SpotLight Color="White" Direction="30,0,-100" Position="-100,180,180"/>
            </Model3DGroup>
         </ModelVisual3D.Content>
      </ModelVisual3D>
   </Viewport3D>
</Page>

When rendered in Kaxaml you should see the following image. Try adjusting the values for the camera slightly to change the view.

XAML 3D Pyramid

NB: In this tutorial we won't look at 3D graphics. They are a complex topic worthy of a separate, future tutorial.

30 January 2013