Is there any event while doing Undo redo

Hi

Is there any event will get fired when we do undo (Ctrl + z) and redo (ctrl + y).
In my application we want to restrict the undo and redo operation to 10 times..
That is the end user can do the undo and redo operation only for 10 times...
How can we do this

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…?

public class CustomCommandHandler: CommandHandler {
and this i have to assign to my model object ...?
Can you help us how we can override and how to assign it back to model...?
am assume the following...
var model = new GraphLinksModel<MyNodeData, String, String, MyLinkData>(); // and initialize it from the XML file that is an embedded resource String xml = Demo.MainPage.Instance.LoadText("FlowChart", "xml");model.Load<MyNodeData, MyLinkData>(XElement.Parse(xml), "MyNodeData", "MyLinkData"); model.Modifiable = true;
model.HasUndoManager = true;
myDiagram.Model = model; myDiagram.CommandHandler = new CustomCommandHandler(); model.UndoManager.MaximumEditCount = 5;
}
but not getting the exact idea...
my requirement is user can be restricted to 5 undo and 5 redo after the count is incremented user cannot do undo and redo...
help us....

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">






**************
Assinging the ND (NodeData)
//
LoadRule function
Public IDiagramModel (string ruleData)
{
var model = new GraphLinksModel<ND, String, String, LD>(); model.Modifiable = true; model.HasUndoManager = true; model.Load<ND, LD>(XElement.Parse(rule), "ND", "LD");
return model;
}
//
//
CommandHandler method
public class CustomCommandHandler : CommandHandler
{
public int UndoCount { get; set; } public int RedoCount { get; set; }  /// /// Method to decide redo operation /// /// return true if count is less than 10 ;false otherwise public override bool CanRedo() { if (this.RedoCount >= RuleConstant.RedoCount) { base.UpdateLayout(); return false; } else { base.UpdateLayout(); this.RedoCount = this.RedoCount + 1; return true; } } /// /// Method to decide Undo operation /// /// return true if count is less than 10 ;false otherwise public override bool CanUndo() { if (this.UndoCount >= RuleConstant.UndoCount) { base.UpdateLayout(); return false; } else { base.UpdateLayout(); this.UndoCount = this.UndoCount + 1; return true; } } public override void OnApplyTemplate() { base.UpdateLayout(); base.OnApplyTemplate(); }       }
//
The follwoing code shows how we are assigning the model object to diagram control
IDiagramModel model = rulesService.LoadRule(XML); ND rootGroupNode = model.FindNodeByKey("0") as ND; this.IsModelInEditSplitMode = false; //model.RemoveNode(rootGroupNode); this.rcDiagram.Model = model; //Undo & Redo CustomCommandHandler objCustomCommandHandler = new CustomCommandHandler(); objCustomCommandHandler.UndoCount = 0; objCustomCommandHandler.RedoCount = 0; this.rcDiagram.CommandHandler = objCustomCommandHandler;
---
What happens is undo and redo functionality works only for the first time..
i mean in another even if i assign another object like..
//Runtime add call loadrule with different data
IDiagramModel model = rulesService.LoadRule(XML); ND rootGroupNode = model.FindNodeByKey("0") as ND; this.IsModelInEditSplitMode = false; //model.RemoveNode(rootGroupNode); this.rcDiagram.Model = model; //Undo & Redo CustomCommandHandler objCustomCommandHandler = new CustomCommandHandler(); objCustomCommandHandler.UndoCount = 0; objCustomCommandHandler.RedoCount = 0; this.rcDiagram.CommandHandler = objCustomCommandHandler;
assing the diagram object ie..this.rcDiagram.Model to another model by calling
Loadrule..then the undo & redo doesn't work..
while debugging what i have found is only for the first time the CompoundEdit object is assigned with object (i guess its a collection)...but after assingin to new model object and while doing Undo & Redo the CompoundEdit object becomes null..i guess because of this (CompoundEdit to NULL) the undo and redo doesnot work
...Please help us....

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.