Part loaded multiple times

I’m using GoXam for Silverlight 1.2.6.4 (finally!) and am seeing the following odd behavior: when you drag a node from a palette and drop it on the diagram, the node is loaded, unloaded, and then loaded again. This not only seems very strange, but it’s throwing off some of the data binding in the custom control which is in my node template.

To reproduce this issue, I modified the Logic Circuit demo as follows:

  1. Add a new class, MyControl, which derives from ContentControl.
  2. In the constructor of MyControl, add handlers for the Loaded and Unloaded events:<span =“apple-style-span”="" style="font-family: Consolas; font-size: 13px; line-height: 18px; white-space: pre; : rgb255, 255, 255; ">[code]Loaded += (sender, args) => { System.Diagnostics.Debug.WriteLine(“Loading {0}, GetHashCode()); };
Unloaded += (sender, args) => { System.Diagnostics.Debug.WriteLine("----Unloading {0}", GetHashCode());};[/code]
  1. Modify the OneInOneOut data template so the NodePanel contains both the original path and a MyControl that displays a textblock with some text as its content.
  2. Run the application and drag a one-in-one-out triangle from the palette and drop it on the diagram. You see a load/unload pair for the object that is dragged from the palette (expected) and then a load/unload/load sequence for the object that actually appears on the diagram. This sequence is not expected.

Is there a way to prevent a new node from being immediately unloaded and reloaded?

When an external drag from a Diagram enters another Diagram, the DraggingTool creates a temporary Node (or more if the selection is multiple). In order for data-binding and drag-over interaction to work correctly, it actually creates the possible node data in the model. Dragging out (“leaving”) causes the temporary data/node to be removed.

The drop causes the temporary data/node to be removed and the real data/node to be created within a transaction.

I don’t know if it would be possible to somehow use the temporary node(s) as the permanent one(s).

I think we’re talking about different things. I understand that dragging will create a temporary node. My issue is that once I complete the drag operation with a drop, GoXam creates a Node in the Diagram. That Node then generates a Loaded event as I would expect (because it’s a new control coming into the visual tree). However, that exact same object then generates an Unloaded event followed by another Loaded event.

Or are you saying that the drag event creates a temporary model object to which the resultant graphical object is bound, but the node is unloaded when the temporary model object is removed and then loaded again with the final object? I’m confused as to why it would be the same graphical Node object. I’d think it would be a new one in this case.

Oh, OK, yes, I misunderstood the situation you are talking about.

I believe that the new Node that got created due to the drop gets put into one Layer and then it gets reparented to be in the desired layer if it’s not the same one. Unfortunately this is necessary in order to get the data-bindings and measurements evaluated in the right environment.

That would totally explain it and gives me a direction to head down. Thanks!