I have a very simple problem where by adding a node to my model doesn’t immediately update the diagram. I’m using an observable collection and a transaction. I have a button, in the button event I create a new node object and add it to the model using myDiagram.Model.AddNode(myNewNode). Doing something else in the diagram (dragging a link for example) makes the newly added node appear.
What am I doing wrong?
By “dragging a link for example”, do you mean drawing a new link?
I’m guessing that the Node that is created for your node data doesn’t have a location. That’s when Node.Location is NaN,NaN.
Do you data-bind the go:Node.Location? If so, check the source value.
Normally, the Diagram.Layout will be invalidated when a node has been added, and it will then make sure the Node.Location is set. So I’m wondering if you have done something to disable that behavior.
Are you using the default Diagram.Layout, or have you set it to an instance of one of the layout classes?
Have you set the DiagramLayout.Conditions (or ConditionFlags in Silverlight XAML)? Might the value not include LayoutChange.NodeAdded?
Yep, I hadn’t set the layout conditions. Good spot.
Well, the default value for DiagramLayout.Conditions includes the LayoutChange.NodeAdded flag, so you shouldn’t need to set it.
[QUOTE=walter] Well, the default value for DiagramLayout.Conditions includes the LayoutChange.NodeAdded flag, so you shouldn’t need to set it.
But I’m using grouping and set layout conditions for that, these would overwrite the defaults unless I explicitly added them.
This issue has raised its head again. I have simplified my problem to be reproduced when I click a button to add a new node to my diagram. The node is added to the model nodesource (which is an observable collection). I have removed all layout conditions (I have also tried explicitly setting LayoutChange.NodeAdded). I have made sure that a location is set for the node. But the node still doesn’t appear in my diagram.
If I hit the button a couple of times first and then add a node by dragging from my palette, the nodes appear. However, repeating this process doesn’t make the nodes from subsequent button clicks appear.
I think I have it sorted, I wasn’t putting my node add method within a transaction. I’ll consider my wrist slapped…