Problem with undo

Hi! i have a problem when i want the undo this action:

Please see the video.

Mi code in this button is:

private void Undo_Click(object sender, RoutedEventArgs e)

Can you helpme please? Because the undo Skip an action

Could you check the model before and after the undo operation, to make sure all of the state is exactly what you are expecting beforehand, and to figure out exactly what state is wrong afterwards?

Please see the video. The result of model

I can’t really tell what’s going on. Are you first loading a model? Then do you load a different model, replacing the first one?

What operation is it that you want to undo? In general, because each model has its own UndoManager, there is no state available about any previous model.

I have a file with two nodes and a link then I combine it with another file generating what the video shows (three nodes and two links).
When I want to undo the combination instead of showing the two nodes and the link I had at the beginning erases everything.

That’s why I was asking about how you were combining the models.

in nodeSource and linkSource i have all nodes and links combined

myDiagram.Model.NodesSource = nodeSource; myDiagram.LinksSource = linkSource;

It’s a little inconsistent to be modifying Model.NodesSource in one half and Diagram.LinksSource in the other half, but I guess that’s OK.

Are you performing all of this model combination / diagram modification within a transaction?

Those lines are within the same method, I do not work with transactions, never use them for the Diagram

Whenever you want to modify a model or any of the data in it, you need to call StartTransaction and CommitTransaction.

Otherwise all of the changes will be bunched together into a single transaction automatically for you, since there’s no way for the UndoManager to know better what your intent is regarding splitting changes into different transactions.

Like this?

myDiagram.StartTransaction("cambioModelo"); myDiagram.Model.NodesSource = nodeSource; myDiagram.LinksSource = linkSource; myDiagram.CommitTransaction("cambioModelo");

Yes. That should now allow undo of the merging of the models.