Binding model nodes

Hello,

I’d like to do something like this

<go:Diagram x:Name=“myDiagram”>
go:Diagram.Model
<go:UniversalGraphLinksModel Name=“testModel” NodesSource="{Binding Items}" />
</go:Diagram.Model>
</go:Diagram>

well, binding observablecollection model nodes with a collection I create.

Is it possible ?

Aurore

Nothing in the Northwoods.GoXam.Model namespace is a DependencyObject, so you cannot bind any of their property values.

We did think about defining DataProvider-like classes, but because most people should want to specify the particular model node data type (and link data type if GraphLinksModel) and because one cannot instantiate generic classes in XAML, we decided not to.

But we could consider alternative solutions…

Hello,

Ok, I have made in a different way.

I have my diagram.xaml window that contains diagram,
and diagramenv.cs which intends to represent the model.

In DiagramEnv, I have defined a GraphinkModel and in the xaml I bind in the following way :

<go:Diagram x:Name=“myDiagram”
Model="{Binding QD_Model}">
</go:Diagram>

But, when I code the command feature in DiagramEnv, I’d like to know what are the selected node for example…
Then I haven’t find a way in my environnement to reach this information.

Well, I can’t separate design and model.

Before I change my code, could you tell me if I miss something.

Thanks
Aurore

As you have already discovered, models don’t really know anything about FrameworkElements such as Parts, so they can’t know about Part.IsSelected. This is particularly true when there might be multiple views (i.e. Diagrams) for a single model – if the notion of selection were in the model, everything would be confused.

That doesn’t mean you couldn’t put the concept of being selected in your model. But I would highly recommend against it.

All of the predefined commands are implemented by the CommandHandler class, which is part of a Diagram, not part of a model. If you are implementing your own commands, they really belong to your view or user-interface layer, not to your model and data. Your commands can be implemented in classes other than CommandHandler, but they do need to refer to Diagram and Part state.

Regarding the main topic, I think we can add Diagram.NodesSource and LinksSource dependency properties that will do what you originally asked for. (Of course, setting/binding the LinksSource property has no effect if the Diagram.Model isn’t an ILinksModel.)

Typically one will still create the model in code and assign it to the Diagram.Model property. If you define your own model class or use a predefined model class like UniversalGraphLinksModel, you will be able to assign the model in XAML. So that won’t change from v1.0.

And you have always been able to bind the Diagram.Model property, so that won’t change either.

Has NodesSource been added as a dependency property yet? I am still unable to databind to it in XAML.

Yes, it is a DependencyProperty in version 1.1.

Data-binding should work as long as you use Mode=TwoWay bindings. That’s documented in version 1.2.