ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Framework Namespace / OperationManager Class / CanUndo Property
Example

In This Topic
    CanUndo Property (OperationManager)
    In This Topic
    Gets a boolean value after checking if the first operation can be undone.
    Syntax
    Public ReadOnly Property CanUndo As Boolean
    public bool CanUndo {get;}
    Remarks
    If the operation cannot be undone, all the operations belonging to its same category are cleared from the undo stack.
    Example
    Undo/Redo Edit Operations
    // Executes an edit operation and demonstrates how to undo the operation programmatically.
    await QueuedTask.Run(() =>
    {
      var editOp = new EditOperation
      {
        Name = "My Name"
      };
      if (!editOp.IsEmpty)
      {
        //Execute and ExecuteAsync will return true if the operation was successful and false if not
        var result = editOp.Execute();
        if (result == true)
        {
          // If the operation was successful, you can undo it
          editOp.UndoAsync();
        }
      }
    });
    Undo/Redo the Most Recent Operation
    // Demonstrates how to undo and redo the most recent operation using the map's operation manager.
      //undo
      if (activeMap.OperationManager.CanUndo)
        activeMap.OperationManager?.UndoAsync();//await as needed
    
      //redo
      if (MapView.Active.Map.OperationManager.CanRedo)
        activeMap.OperationManager?.RedoAsync();//await as needed
    }
    Dockpane undo / redo
    {
      // in order to find a dockpane you need to know its DAML id
      pane = FrameworkApplication.DockPaneManager.Find(dockPaneID);
    
      // get the undo stack
      OperationManager manager = pane.OperationManager;
      if (manager != null)
      {
        // undo an operation
        // Use await with UndoAsync and RedoAsync
        if (manager.CanUndo)
          manager.UndoAsync().Wait();
    
        // redo an operation
        if (manager.CanRedo)
          manager.RedoAsync().Wait();
    
        // clear the undo and redo stack of operations of a particular category
        manager.ClearUndoCategory("Some category");
        manager.ClearRedoCategory("Some category");
      }
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also