Problems with copy and paste again

I have Nodes. The Node.Data is from Type Element. This Element has a List of properties where the Nodes Visual is bound to. But the values of this properties are not fix in the Element, they came from a Dictionary where for every Element there are Lists of different property values.
So if I want to use copy and paste, it is not done with copying the node. I must have a way to create a new dictionary entry for the new node and copy the originals list of property values to that new entry.

I did a ugly hack with the CommandHandler.Copy and CommandHandler.Paste Methods where I save a temporary list of the copied Nodes and on paste search them in the Dictionary to copy their properties. But this is not working if I try to copy a group, since only the group is selected and so on…

So I need some entry point in GoXam where I can do something on every node copy even if it comes from copying a group.

I tried CommandHandler.CopyToClipboard and PasteFromClipboard but I don’t see a way to give IDataCollection further information of my properties. I thought I can serialize my dictionary somehow and give it to the IDataCollection, so I can pull my properties out of it on PasteFromClipboard.

It sounds like you really should not be doing anything at the Diagram/FrameworkElement level, but at the GraphLinksModel level.

In particular I think you want to override GraphLinksModel.CopyNode1 and CopyLink1.

I don’t get how CopyNode1 is working.
It was called on ctrl-c and ctrl-v, but I see no difference in the data on first view.
How can I see if I inserted something? Where are the original Nodes and where the copied?

Before I tried CopyNode1 I was able to make some progress with PasteFromClipboard and CopyToClipboard until I realized that the Nodes in the Collection of PasteFromClipboard are not the Nodes that are really inserted in NodeSource. So I can’t use this approach, cause I have that Dictionary<Element, Properties>.

CopyNode1 is called in order to make a copy of the model data. If you node data object has a Dictionary in it, wouldn’t you want to make an appropriate copy of it then, in your override of CopyNode1?

Overriding the behavior at the model level means that you can customize the behavior when node (data) is copied for any reason, not just copy or paste.

Hi Walter,
I try it again:
The Dictionary is not in the Node. The Node holds a temporary copy of property values. These property values are coming from an external Dictionary where I hold different property values for each node. Not just one set of property values - no many sets of property values for each node.
So on paste I must add a new Entry in this Dictionary with the new Node a Key and the copied property values a Value.

So I must find a entry point where I know the Nodes that are copied to clipboard and the new Nodes that are added to NodeSource. Then I can add the new Nodes to my Dictionary and copy the property sets from the oldNode as Value for that entry.

So you have per-node data stored elsewhere, yes? And that data is in a Dictionary whose key is the unique id or key of the node data within the model?

But at the time CopyNode1 is called, it doesn’t have a new unique id yet because MakeNodeKeyUnique hasn’t been called yet (after all, CopyNode1 has just constructed the copied object).

OK, instead of overriding CopyNode1, implement a model Changed event handler that looks for ModelChangedEventArgs.Change == ModelChange.AddedNode. That will tell you whenever any node data has been added to the model.