Hi
The literal answer to your question is that you can check for model.Changed events that have ModelChangedEventArgs.Change == ModelChange.FinishedUndo or .FinishedRedo.
But at that time it’s too late – the Undo or Redo has already been done. Instead it would make more sense to override CommandHandler.CanUndo() and CanRedo() to return false when the UndoManager.CompoundEdits.Count >= 10.
However the real answer to your query is to set:
myDiagram.Model.UndoManager.MaximumEditCount = 10;
So do you mean to say i must inherit from CommandHandlerclass in order to implement the Undo and Redo functionality…?
However the real answer to your query is to set: myDiagram.Model.UndoManager.MaximumEditCount = 5;
Why would someone write a spec that REQUIRES undo/redo to be limited?
Possibly there is a memory issue. All the undo/redo compound actions are stored in memory. For some Go users the Diagram is only one of their components like us. We will display multiple diagrams and other components within our integrated application. Our undo/redo is controlled by our framework and all components are undoable include open/close the components. It seems not possible undo unlimited actions.
The followings are my code structure
<Grid x:Name="RuleCanvasLayout"Width="Auto"
HorizontalAlignment="Stretch"
ShowGridLines="False"> <Canvas x:Name="rcCanvasdrawingArea"
VerticalAlignment="Top"
Ish*tTestVisible="True"> <toolkit:BusyIndicator x:Name="bysIndicator"
BusyContent="loading................"
Foreground="Black">
<go:Diagram x:Name="rcDiagram"
Width="Auto"
Height="Auto"
Margin="10,25,0,10"
HorizontalAlignment="Left"
VerticalAlignment="Top"
AllowClipboard="True"
AllowCopy="False"
AllowDelete="False"
AllowMove="False"
AllowReshape="True"
AllowResize="True"
AllowUndo="True"
Background="White"
BorderBrush="{x:Null}"
LinkTemplate="{StaticResource LinkTemplate}"
MaximumSelectionCount="1"
NodeTemplateDictionary="{StaticResource NodeTemplateDictionary}"
Padding="75">
**************
As I understand your requirement now, you want to limit the total number of successful calls to UndoManager.Undo() to be less than some constant number (and the same for Redo).
That is unlike UndoManager.MaximumEditCount, which is intended to limit the history (and maybe memory usage) by limiting the length (depth) of the history, without limiting the number of times the user can repeat pairs of Undo and then Redo commands.
The Diagram.CommandHandler is not automatically replaced when you replace the Diagram.Model. I think resetting your UndoCounter and RedoCounter to zero should be sufficient.
I think your problem is that your CanUndo() and CanRedo() predicates are incrementing your counters. Predicates should not modify state. Overrides of Undo() and Redo() ought to be incrementing your counters.
By the way, calling FrameworkElement.UpdateLayout() is pointless on a CommandHandler object.