protected virtual void OnBeforeUndo(BeforeUndoEventArgs e)
 {
     if(BeforeUndo != null)
     BeforeUndo(this, e);
 }
 public void Undo()
 {
     if(!CanUndo)
     throw new CommandHistoryEmptyException("Nothing to undo.");
       IUndoableCommand command = commandHistory.Peek();
       BeforeUndoEventArgs args = new BeforeUndoEventArgs() { Cancel = false, Command = command };
       OnBeforeUndo(args);
       if(!args.Cancel)
       {
     command.Undo();
     undoneCommands.Push(commandHistory.Pop());
     OnCommandHistoryChanged();
       }
 }