0

DataTemplate3D for custom ModelVisual3D Xml/View

Michael Powell 10 years ago updated 10 years ago 4
I've got a custom ModelVisual3D, literally I extended into a Xml/View to build a model. I will likely have several of these animals, but each of them are a ModelVisual3D.

I am studying the WPF DataTemplate example, and it is interesting, data template acts as a kind of bridge into the 3D model?

I'm not sure what CreateItem is all about, except possibly a convention integrating with the sister ItemsVisual3D?

I wouldn't have such a thing in my model. In fact, I'm not sure I would potentially have one data template per model in the view, the content of which is the view instance?

It's making some sense grasping the connecting tissue.

Thank you...
I see the call:

var model = this.ItemTemplate.CreateItem(item);

The trick with this is, whereas with ItemSource being a collection (flat?) of models, I'd like to deal with a defined model Xaml/View, as a tree/hierarchy of models.

Likely still connecting with the data template... Likely...
Based on the example in the MainWindow, I take it that the ItemsVisual3D acts as a container for whatever actual models are contained by the DataTemplate3D?

In the example case, the bindings are expressed in the view. In my case, I've got bindings in a separately derived ModelVisual3D View / Xaml.

Following which, we would simply be talking about appropriate binding paths, view models, and things of this nature?
This is a WPF confusion of mine.

In my Xaml/View, I am deriving from ModelVisual3D, throughout which I am making several bindings in the Xaml itself.

However, in the example, I am gather that Center, Radius (through SphereVisual3D), and plausibly Material as well (through one of its base classes), are actually dependency properties, not unlike the 'DataContext' I would need to add through the DataTemplate3D.

<MyUserControl.Resources>
    <local:DataTemplate3D x:Key="Template1">
        <h:SphereVisual3D Center="{Binding Position}" Material="{Binding Material}" Radius="{Binding Radius}"/>
    </local:DataTemplate3D>
</MyUserControl.Resources>


So I need to do a couple of things? This is where I am a bit confused.

  • First, add in the requisite DependencyProperty(ies) in my derived ModelVisual3D.
  • Next, bind some level of changeable properties to DependencyProperty(ies) in the derived model itself. Since, internally, DataContext and therefore implied data bindings don't work from ModelVisual3D, the need to be exposed differently.
  • Finally, decide how to route that data to the DataTemplate3D; simple enough, I see that much resolving as it stands.
Along the lines, I gather that when SphereVisual3D sees a changes to Center, for instance, changes are communicated through GeometryChanged, OnGeometryChanged, and finally 'Tessellate', at least in the case of something like a MeshVisual3D.

The point is, those are communicated via DependencyProperty(ies), which at some level has some comprehension of the components of the overall model, how to calculate changes to various bits, points, colors, and so on.

At this point I think I see what I am missing; instead of 'bindings' I actually need 'DependencyProperty(ies)'.
Well... After some trial and error, and doing the DependencyProperty dance across a couple of views, view models, including several value changed listeners, I was finally able to get something more or less wired up.