Hi,
I'm trying to add links automatically when a node is added to the diagram. The linking is done based on the drop location relative to the selected node in the diagram.Thank you.The issue is the linking is done successfully. But, for some reason after the linking has been done the link is removed and also the new node that was added. And the node is added again to the diagram. Below is the activities that happens when a new node is added (Used Debug.WriteLine to print out the Change type and the source node key):
[Note: “New Key” is the key of the data that is passed in the event argument(e.Data)]
AddedNode
New Key: 3
StartedTransaction
AddedFromNodeKey
New Key: 2
AddedToNodeKey
New Key: 3
CommittedTransaction
RemovedToNodeKey
New Key: 3
StartedTransaction
CommittedTransaction
StartedTransaction
CommittedTransaction
RemovingNode
New Key: 3
RemovedNode
New Key: 3
StartedTransaction
AddedNode
New Key: 3
AddedToNodeKey
New Key: 3
RemovedToNodeKey
New Key: 3
CommittedTransaction
StartedTransaction
CommittedTransaction
StartedTransaction
CommittedTransactionBelow is the code snippet of the function handling Diagram’s Model Changed event
if(e.Change == ModelChange.AddedNode) { if(diagram.SelectedNode != null) { e.Model.StartTransaction("AutoLink"); if( (e.Data as NodeData).Location.X > diagram.SelectedNode.Location.X) diagram.Model.AddLink(diagram.SelectedNode.Data, null, e.Data, null); else diagram.Model.AddLink(e.Data, null, diagram.SelectedNode.Data, null); e.Model.CommitTransaction("AutoLink"); } }
I’m not able to understand why the node is added & then removed & added again. Why the link is removed?
I’ve defined the incoming & outgoing port using go:Node.ToSpot = “MiddleLeft” & go:Node.FromSpot = “MiddleRight” on the go:NodePanel in the node’s DataTemplate.
I’m using Silverlight 4.0.60129.0, .Net 4 framework, goSilverlight 1.2.6.4