MakeNodeKeyUnique Behaviour


I'd like to know why the behaviour/implementation of MakeNodeKeyBehaviour for GraphLinksModelNodeData has changed between v1.2.6.4 and v.
In v1.2.6.4, I had code that looks similar to the following:
public class MyNode : GraphLinksModelNodeData
public MyNode()


public class MyLinkData : GraphLinksModelLinkData
public MyLinkData()
var model = new GraphLinksModel();
ctlDiagram.Model = model;
I then had a pallete where I drag-dropped nodes onto the diagram's surface.
The drop code looked as follows:
ctlDiagram.Model.AddNode(new MyNode {
Key = m.Key,
Text = m.Name,
Location = e.Options.RelativeDragPoint
If I dropped duplicate nodes with same key onto the surface it modified the duplicate node's key to ensure node key uniqueness.
However, as of I get an InvalidOperationException saying "Found duplicate key '1' for node; override MakeNodeKeyUnique to modify data"
I'm a bit confused as to why the older implementation worked happily and why the newer one breaks.
Secondly, does it really matter what the key type of the node is? I know that if I make the key type = string the problem will go away.

I cannot explain that with the information I have.

When I diff the sources between 1.2.6 and 1.3.3, the only difference in the GraphLinksModel and …NodeData and …LinkData files is the change relating to Guids, as documented in the release notes.
(Well, there are also changes in the comments, including doc strings, but never mind those.)

Is this for Silverlight or for WPF? I ask because the built-in drag-and-drop support is different for the two platforms.

Are you using a GoXam Palette control or something of your own construction? I’m guessing it’s the latter, because one doesn’t normally need to write code to handle drops that are dragged from a Palette.

Thanks for the response and sorry for not being clearer.

- This is for Silverlight
- I'm not using the GoXam Pallete

I just tried this, using GoSilverlight with Silverlight 5.

First I modified the GoSilverlightBasic demo app so that the model use “int” instead of “string” as the node key type. As expected, drag-and-drop from the Palette still worked just fine.

Then I modified the NodeMenuClick method to insert a copy of the data into the main diagram:

var data = ((PartManager.PartBinding)elt.DataContext).Data as MyNodeData; //MessageBox.Show("Node color: " + data.Color); myDiagram.StartTransaction("insert"); myDiagram.Model.AddNode(data.Clone()); myDiagram.CommitTransaction("insert");
When repeatedly executing this context menu command on a node in the palette, this also worked fine, without any exception and properly assigning new keys to the added node data.

So I do not understand how your situation is different from the one I just described.

Please note that I’m using

To repo this error I did the following:
1) Created a new Silverlight 5 application
2) Added a reference to GoXam Silveright
3) My MainPage.xaml looks as follows:
<UserControl x:Class="GoXam5Test.MainPage"
d:DesignHeight="300" d:DesignWidth="400">

3) My code-behind looks as follows:
public MainPage()
#region Nested Types
public class MyNodeData : GraphLinksModelNodeData
public class MyLinkData : GraphLinksModelLinkData
#region Member Methods
private void InitInstance()
var model = new GraphLinksModel();
model.NodeKeyPath = "Key";
model.LinkFromPath = "From";
model.LinkToPath = "To";
model.NodeKeyIsNodeData = false;
model.Modifiable = true;
model.NodesSource = new ObservableCollection();
model.LinksSource = new ObservableCollection();
ctlDiagram.Model = model;
ctlDiagram.Model.AddNode(new MyNodeData { Key = 1 });
ctlDiagram.Model.AddNode(new MyNodeData { Key = 1 });

The line in bold will fail with but will succeed with

I tried your code, and as you say it failed with But it also failed with

I changed the code to use “int” instead of “long”, and it worked with not only but and also.

So I think the problem is the use of “long” instead of “int”, not a change between 1.2 and 1.3.
GoXam models only know how to make string, int, and Guid type node keys unique.
But you can easily implement what you want by overriding MakeNodeKeyUnique.

Thanks Walter, you are correct, it’s a long issue.

One last question, when defining a diagram model does it really matter what the key type is for the node, whether it's string, int or Guid? If the GoXam model might change a node's key to ensure uniqueness then doesn't that mean I shouldn't really rely on that key for anything useful? (excluding the Guid case of course)

Well, the data type should matter to the code that makes use of the property, so that it can compile.

And it only gets modified when the node data is added to the model, because only at that time is there any context in which uniqueness would make any sense. That assumes, of course that the key value isn’t modified out from under the model. Not much we could do if that happens.