Subgraph size uncontrolled

I was trying to make a subgraph that allows the user to drag and drop GoNode objects inside it.

I found a probem in this procedure that happened to exist in the SubGraph sample application.

If the user resized the subgraph before dropping the node, then dropped the node near the resized side, the resized side moves again making a new margin between it and the newly dropped object.

How can I prevent the SubGraph from automatically resizing??

Another question: What is the best way to support external dragging and dropping from a GoPalette inside my subgraph?

Resizing a GoSubGraph will change the margins. So when there is a large margin to begin with, when you add an object in the margin, it has to get bigger to maintain the same size margin.
For handling drag-and-drop from a GoPalette (or other GoView), the GoView should be accepting drops by making a copy of the dragged selection and adding it/them to the view’s document. This is standard behavior.
But if you are talking about wanting to have those objects automatically be added to the subgraph that they are dropped on, you could try setting GoView.ExternalDragDropsOnEnter to true. This will cause the GoView to handle the drag enter by actually doing the drop to add a copy of the selection to the document and using the view’s dragging tool to handle the move within the view. This will basically get the behavior you want, except that I’m not sure it will support the Shift-key modifier the way you want. You’ll need to try this.
If that doesn’t work for you, the more general solution is to implement a GoView.ExternalObjectsDropped event handler to detect that the newly added object is inside a subgraph, and then reparent it to be a child of the subgraph. You’ll need to handle the case where there are multiple possible subgraphs, of course.

Thanks for your reply.
I used your first idea about setting GoView.ExternalDragDropsOnEnter to true. It worked fine and I can now add objects from the palette to a GoSubGaph.
The problem is the copy of the node that is added once it enters the view.
It is removed once I continue dragging to a GoSubGraph. But I want to make this node invisible till that happens.
And I also want it to skip the undo manager. Because when I Undo after dropping inside the GoSubGraph, it is first removed from the SubGraph and appears on the view, then removed from the view in a second transaction (take 2 steps to make full undo).
can you help me with that?

I would think that hiding the object while the user is dragging would be confusing and/or disconcerting to the user. But you could do that by adding a GoView.ExternalObjectsDropped event handler that made the objects in the Selection not Visible. Then in the SubGraphDraggingTool you could modify DoDragging to make the objects in the Selection Visible again.
For the undo problem, I’m not sure, but you could try overriding GoView.OnDragEnter. Completely untested code:
protected override void OnDragEnter(DragEventArgs evt) {
bool oldskip = this.Document.SkipsUndoManager;
bool skip = this.ExternalDragDropsOnEnter && !IsInternalDragDrop(evt) && CanInsertObjects();
this.Document.SkipsUndoManager = skip;
this.Document.SkipsUndoManager = oldskip;

I dont want to hide the object while it’s being dragged. But when I press Shift to execute the DoDragging of my DraggingTool, one object appears on the view once I enter the GoView, and another one moves with the mouse cursor till I drop it on the GoSubGraph.
I modified the code of SubGraph appliction (by adding a small palette and setting the GoView.ExternalDragDropsOnEnter to true) and the same thing happened.

When I only drag the object without pressing the Shift key, no extra objects appears
However, in both cases (with the Shift key pressed or not), calling Undo() causes the moving of the object from its dropping point to that point at the edge of the GoView, then I have to Undo() once more to remove it completely fromt the view.
To wrap things up: With GoView.ExternalDragDropsOnEnter set to true, one object is dropped once I enter the GoView, and another object is dropped where I release the mouse.
When I call Undo(), that first objects appears.

You can certainly change the SubGraphDraggingTool not to work differently when Shift is held down.
I’m not sure what to do about the split transaction. There might be some way to put everything into a single transaction, or as a work-around, to merge the two transactions. I suggest for now you just live with the need for the extra undo.