ObservableCollection Changing Between Undo/Redo

I have an observable collection with dynamic ports as described here: http://www.nwoods.com/forum/forum_posts.asp?TID=5141&title=dynamic-ports-not-extending-past-edge-of-node

Here is an example of what is happening…

Initial ports: L1, L2, R1, R2, L3

  • Move port ‘L3’ and it gets renamed to ‘T1’, making the ports: L1, L2, R1, R2, T1
  • Move port ‘T1’ and it gets renamed to ‘R3’, making the ports: L1, L2, R1, R2, R3
  • Move port ‘R3’ and it gets renamed to ‘B1’, making the ports: L1, L2, R1, R2, B1

  • Undo, ports become: L1, L2, R1, R2, R3
  • Undo, ports become :L1, L2, R1, R2, T1
  • Undo, ports become: L1, L2, R1, R2, L3


    The problem I am having occurs when I try to redo those changes. Here is what is happening…


    - Redo, ports become: L1, L2, R1, R2, B1
    - Redo, ports remain: L1, L2, R1, R2, B1
    - Redo, ports remain: L1, L2, R1, R2, B1


    Undoing between any of the redos produces the correct results, so it’s something with the redo only. Any ideas what might be happening? Or where I can best track down what is happening?


    Thanks
    Ryan

So an undo after the last redo results in the last item being R3?

You can print the contents of each transaction/CompoundEdit in the UndoManager history to make sure that all of the ModelChangedEventArgs are what you expect and have the right values for old and new values.

I am guessing that some call to ChangeState is having unexpected side-effects. But it isn’t clear why only in one direction.

I found the problem… I was copying the ports from the collection into a new collection before starting to make changes to submit for the model change for the old value, but was just passing the actual collection as the new value so it was updating there all along. I’ve copied the new values into another collection before sending them to the model change and the issue has been fixed.

Thanks for your time.
Ryan