A little while ago I wrote an article for www.codeproject.com about using 3D meshes in WPF that were hosting 2d controls, such as Grids, Lists, and User controls. The article which can be found right here if you are interested.
The problem with the way that I did things in that article was that I used some fairly complicated
DataTemplates within the actual 3d model XAML. These
DataTemplates also had to include ContentControls that would also look at resources for their own content.
It did work, but now that .NET 3.5 has been released, there is a much better way. This better way comes in the form of a new class, called
Viewport2DVisual3D. What this new class allows you to do is to create a 3d model, but it also allows you to host a 2d
UIElement on a 3d Material, and the 2d UIElement is fully interactive. Its probably best if I show you and example so, ill do that now.
Title=”Viewport2DVisual3D” Height=”300″ Width=”300″>
<!– UI Mesh –>
<MeshGeometry3D x:Key=”uiMesh” TriangleIndices=”0,1,2 3,4,5″
Positions=”-1,-1,2 1,-1,2 1,1,2 1,1,2 -1,1,2 -1,-1,2 “
TextureCoordinates=”0,1 1,1 1,0 1,0, 0,0 0,1″/>
<!– UI Mesh Rotation –>
<Storyboard x:Key=”uiSpin” RepeatBehavior=”Forever”>
<DoubleAnimation BeginTime=”00:00:00″ Duration=”00:00:15″
Storyboard.TargetName=”uiRotate”Storyboard.TargetProperty=”Angle” From=”0″ To=”360″/>
This small example is a simple 3d mesh, with a StackPanel filled with 4 * Button. When one of the buttons is clicked a MessageBox is shown with the content of the clickedButon as the Message.
Here is a small demo project if you would like to try this out for yourself viewport2dvisual3d.zip