Problem with add new node to diagram

Hi,
We are using “Diagram” Object to illustrate Family relationship model.
A Node is a family member, and a Link is connection between Family members.

For a Node, We have created class “baseNodaData” that extends class GraphLinksModelNodeData<String>.
This class have the properties as follows:
string Caption.
string Picture .
Guid NodeId.
Then, we have created class “MyNodeData” that extends our “baseNodaData” class, with it’s own properties (like “ChildPicture”).


Then. We have created a “Pallete” object, that shows all the nodes available and managed to drag them to the Diagram. each node is a “MyNodeDate” instance.


Everything worked Fine! we saw the node picture and caption and the child picture on every Node in the pallete and in the diagram.


Now, we wanted to remove the pallete from our Product, instead, we want to create nodes on the Diagram directly. that mean, from view model create new instance of “MyNodeData” and give it default values (exactly as we did at the pallete). and show it on the diagram.


The problem that it’s doesn’t show the picture or the caption. and instead, on the diagram we see the line “PartManager.PartBinding of Node to 4355-35556566-1231…” i thought it’s some binding problem (we are working with MVVM pattern), but i couldn’t see any problem, more than that, we didn’t changed anything. the only change is creating the myNodeData object directly on the Diagram instead of dragging it from the pallete… what can cause that problem??


the code to show it on the diagram is:
DiagramModel.AddNode(element); //element is “MyNodeData” instance.Mydiagram.Model = DiagramModel;

That’s probably because you have a {Binding} without specifying a Path=Data.Caption or something similar.

I think you are doing the right thing by calling Model.AddNode with an instance of your node data. You can find examples of this in the samples where a command programmatically adds a node.

Hi. i’m doing it in the right way:

<Grid Grid.Row="1" Background="Transparent">
    <Image Source="{Binding Path=Data.Picture, Converter={StaticResource theImageSourceConvertor}}" Stretch="Fill" MaxHeight="50" MaxWidth="50"/>
</Grid>
As i mentioned, it had worked fine when i had dragged element from the pallete to the Diagram, and i did no changes at all, beside creating the 'MyNodeData" and added it to the diagram threw code (and not by dragging)

Surely it wasn’t removing the Palette control that caused the Diagram to “break” how it displays its nodes? Are you sure that you have the right templates in your Diagram, and that removing the Palette didn’t break those templates?

Also, do the nodes in the Diagram appear correctly if the data is initially part of the model, rather than added dynamically? That way you can determine whether the way that you create new nodes is the problem or whether the templates for all nodes in the diagram are broken somehow.

I didn’t removed the pallete yet… user can still drag an element from the pallete to the diagram, and in that way it’s working fine! the nodes are appear as they should be.
the problem happen only on elements that are added to the diagram not dynamically… mean by creating instance of “MyNodeData” and add them by DiagramModel.AddNode(element);

OK, so now you know there’s something wrong with the data that you are adding to the model.
Maybe the Category property?

Walter.
Thanks you found the problem :)
We didn’t assigned value to the “Category” property.
Can you explain the property?

The value of the data’s Category property is used to look up the DataTemplate in the Diagram’s DataTemplateDictionary.

There is a section in the GoXam Introduction document that explains it. Many of the samples use this technique too.