Undo After Resize Only Shifts Location

I am experiencing some strange behavior with Undo after resizing my nodes. My nodes LocationSpot is set to TopLeft, and are not Reshapable, so resizing will generally change the node.Location. When I Undo, the nodes are shifting their location back to the previous spot, but aren’t returning to the previous size.

Also, if I resize from the bottom-right corner (which keeps the location the same) and then Undo, the node is actually removed from the diagram.

Any insight into what might be causing this and how I can fix it?


I don’t see that behavior in the DraggableLink sample, for example. But one difference is that the LocationSpot is Center in that sample.

But if I change the LocationSpot in that sample to be TopLeft, undo/redo still work fine. However, the resizing behavior is changed to be different (and not what people would expect, I think).

Do you have TwoWay data-bindings on the Node.Location and on the resized element’s Width and Height properties?

Have you modified any tools?

Yes I have TwoWay bindings for Location, Width, and Height… I have modified several tools, but even after reverting my ResizingTool to the default, the problem stays the same.

Maybe you can figure out what’s going on by looking at the UndoManager’s history of edits.
The best sample that deals with this is UpdateDemo.

Here’s some code to dump the state of the UndoManager:

System.Diagnostics.Trace.WriteLine(myDiagram.Model.UndoManager.ToString()); foreach (IUndoableEdit edit in myDiagram.Model.UndoManager.CompoundEdits) { System.Diagnostics.Trace.WriteLine(" " + edit.ToString()); UndoManager.CompoundEdit cedit = edit as UndoManager.CompoundEdit; if (cedit != null) { foreach (IUndoableEdit u in cedit.Edits) { System.Diagnostics.Trace.WriteLine(" " + u.ToString()); } } }
You might want to call this from a keyboard command as you are doing things.

From my resize compound edit, the Edits I have are:

It doesn’t seem to be recording anything in regards to the size.

The ResizingTool.DoResize method, which is called upon a successful resizing operation, sets the Node.Location and the AdornedElement.Width and .Height.

Are you sure you have TwoWay data-bindings of Width and Height on the element that is being resized?

Yes, they are definitely TwoWay bound.

Do the Width and Height property setters on the node data class call RaisePropertyChanged when the value changes, after setting the member data?

Have you overridden any methods on the node data class, the model, or the UndoManager and perhaps forgotten to call the base method when you should have?

These are all unlikely, but that’s all I have left that might help you.