Freigeben über


What’s new in WPF 3.5

With the release of WPF 3.5 beta 2 (download here: https://www.microsoft.com/downloads/details.aspx?FamilyId=D2F74873-C796-4E60-91C8-F0EF809B09EE&displaylang=en), we’ve added some exciting new features to WPF 3D. At a very high level these can be grouped in to two main additions: UIElement3D and Viewport2DVisual3D. Over the next couple of weeks we’ll be adding examples and tips and tricks to the blog on these new additions, but for now we’ll start with a quick overview of what both of these provide.

UIElement3D

In the 2D world, UIElement adds layout, input, focus and eventing on to Visual. UIElement3D brings these same things (except no layout) to 3D. What this means is that the standard events and means of adding event handlers that you’re used to with UIElements now applies in the 3D world with UIElement3D.

UIElement3D itself is an abstract class that derives from Visual3D. To make it useable out of the box without having to derive from UIElement3D yourself, we’ve provided two new classes: ModelUIElement3D and ContainerUIElement3D.

ContainerUIElement3D does exactly what its name says. It is a container for other Visual3Ds. It has one main property, Children, which is used to add and remove 3D children. The ContainerUIElement3D doesn’t have a visual representation itself, but rather is just a collection of other 3D objects.

ModelUIElement3D has one property, Model, which is the Model3D that should be displayed to represent the UIElement3D. It has no children itself, and in some ways you can think of ModelUIElement3D like a Shape in the 2D world.

If you’re familiar with ModelVisual3D, then ContainerUIElement3D and ModelUIElement3D should look very familiar. The difference is we’ve gone and split the functionality of ModelVisual3D (i.e. a model and children) in to two separate classes, one with a model and the other with children.

With these then, making use of layout, focus and eventing is very easy. For instance, say you want to create a 3D object that responds to mouse events, you can just do:

                <ModelUIElement3D  MouseDown="OnMouseDown"/>

And then in the code behind have:

      protected void OnMouseDown(object sender, MouseButtonEventArgs e)

      {

          Console.WriteLine("Hello");

      }

If you have experience adding event handlers in the 2D world, then this should look immediately familiar. In fact it’s exactly the same, and UIElement3D is going to handle the same routed events that a UIElement deals with. With the addition of UIElement3D you now get all the great functionality that UIElement provided to 2D, but now in the 3D world!

Viewport2DVisual3D

The second main addition is Viewport2DVisual3D which enables you to put interactive 2D on 3D in WPF. If you’ve used the 3DTools work that was released shortly after the 3.0 release of WPF, Viewport2DVisual3D will look very familiar to you. With 3.5 though we’ve fully integrated 2D on 3D in to WPF rather than requiring a separate DLL to have this feature. The 2D and 3D trees are also integrated now, so if you walk up to a 2D visual on 3D and ask it for its parent, it will tell you the 3D object it is on.

Viewport2DVisual3D derives from Visual3D and has three main dependency properties: Visual, Geometry and Material.

Visual – This is the 2D Visual that will be placed on the 3D object.

Geometry – The 3D geometry for the Viewport2DVisual3D

Material – This describes the look of the 3D object. You can use any material you want. For the material that you want to have the Visual be placed on, you simply need to set the Viewport2DVisual3D.IsVisualHostMaterial attached property to true.

Below is a XAML example using Viewport2DVisual3D

<Viewport2DVisual3D Geometry="{StaticResource plane}">

    <Viewport2DVisual3D.Material>

          <DiffuseMaterial  Viewport2DVisual3D.IsVisualHostMaterial="true" />

        </Viewport2DVisual3D.Material>

       

        <Button>3.5!</Button>

      </Viewport2DVisual3D>

The above is a very quick overview of what is added in 3.5, so expect more posts on more specific details as well as some code samples on how to use it.

-Kurt Berglund

Comments

  • Anonymous
    July 30, 2007
    Kurt recently put out an overview on the V3.5 interactive 3D feature additions (UIElement3D types and

  • Anonymous
    July 30, 2007
    Kurt recently put out an overview on the V3.5 interactive 3D feature additions (UIElement3D types and

  • Anonymous
    July 30, 2007
    A BumpmapMaterial class would be even better :)

  • Anonymous
    July 31, 2007
    The comment has been removed

  • Anonymous
    July 31, 2007
    Neat, I've just found this page and it's certainly going in my favorites. One minor point, and I hate to bring it up given my own laughable English skills, but it seems the spell checker misled you. "The second main edition is Viewport2DVisual3D" should be "The second main addition is Viewport2DVisual3D" or perhaps "The second major addition is Viewport2DVisual3D"

  • Anonymous
    August 04, 2007
    Le support du déploiement XBAP dans Firefox, la possibilité d&#39;appeler un service WCF depuis une XBAP

  • Anonymous
    August 05, 2007
    Some cool things coming in WPF 3.5 . My favorite is the baked-in support for controls on 3d surfaces.

  • Anonymous
    August 20, 2007
    Any sign of 3D lines in an upcoming release?

  • Anonymous
    August 29, 2007
    I'm fairly poor at 3D. I was optimistic when WPF came along because I felt it might suddenly turn me...

  • Anonymous
    September 26, 2007
    The comment has been removed

  • Anonymous
    December 08, 2007
    The first version of WPF was released as part of .NET Framework 3.0 in November 2006. On 11/16/2007,

  • Anonymous
    March 17, 2008
    I'm converting code from 3D Tools' InteractiveVisual3D to Viewport2DVisual3D. I was able to use the former to drag/drop across visuals.  That is, I have one visual with one form (user control), and another visual with another form, and I could drag/drop from one form to the other, in 3D. Is this not supported with V2dV3d?

  • Anonymous
    June 28, 2008
    Some cool things coming in WPF 3.5 . My favorite is the baked-in support for controls on 3d surfaces. There was an add-in for this for previous versions (which worked but was not completely integrated), but this is great news for future applications!