LEADTOOLS Annotations for WPF and Silverlight (Leadtools.Windows.Annotations assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.31
BeginUndo Method
See Also 
Leadtools.Windows.Annotations Namespace > AnnAutomation Class : BeginUndo Method



The BeginUndo Method supports WPF/Silverlight.

The BeginUndo Method is available in LEADTOOLS Document and Medical Imaging toolkits.

Creates a new undo node in this AnnAutomation object. Supported in Silverlight, Windows Phone 7

Syntax

Visual Basic (Declaration) 
Public Overridable Sub BeginUndo() 
Visual Basic (Usage)Copy Code
Dim instance As AnnAutomation
 
instance.BeginUndo()
C# 
public virtual void BeginUndo()
C++/CLI 
public:
virtual void BeginUndo(); 

Example

This example will manually add a new rectangle object to an automation object and then start editing it.

Visual BasicCopy Code
Private Sub AnnAutomation_BeginUndo(ByVal automation As AnnAutomation)
   ' first create a new undo node
   automation.BeginUndo()
   Try
      ' add a new rectangle object
      Dim rectObj As AnnRectangleObject = New AnnRectangleObject()
      rectObj.Rect = New Rect(100, 100, 200, 200)

      rectObj.Stroke = Colors.Blue
      rectObj.StrokeThickness = 2.0
      rectObj.Fill = Colors.Yellow

      automation.Container.Children.Add(rectObj)

      ' "select" this object
      automation.StartEditing(rectObj, False)

      ' commit the undo node
      automation.EndUndo()
   Catch ex As Exception
      ' in case of errors, cancel the undo node
      automation.CancelUndo()
      Throw ex
   End Try

   MessageBox.Show("Object has been added as is now selected.  Next will call //Undo// to undo the operation")
   automation.Undo()
   MessageBox.Show("Operation has been undone.  Next will call //Redo// to redo the operation")
   automation.Redo()
   MessageBox.Show("Object should be back and selected")
End Sub
C#Copy Code
private void AnnAutomation_BeginUndo(AnnAutomation automation)
{
   // first create a new undo node
   automation.BeginUndo();
   try
   {
      // add a new rectangle object
      AnnRectangleObject rectObj = new AnnRectangleObject();
      rectObj.Rect = new Rect(100, 100, 200, 200);
      rectObj.Stroke = Colors.Blue;
      rectObj.Fill = Colors.Yellow;

      rectObj.StrokeThickness = 2.0;

      automation.Container.Children.Add(rectObj);

      // "select" this object
      automation.StartEditing(rectObj, false);

      // commit the undo node
      automation.EndUndo();
   }
   catch(Exception ex)
   {
      // in case of errors, cancel the undo node
      automation.CancelUndo();
      throw ex;
   }

   MessageBox.Show("Object has been added as is now selected.  Next will call //Undo// to undo the operation");
   automation.Undo();
   MessageBox.Show("Operation has been undone.  Next will call //Redo// to redo the operation");
   automation.Redo();
   MessageBox.Show("Object should be back and selected");
}
SilverlightCSharpCopy Code
private void AnnAutomation_BeginUndo(AnnAutomation automation)
{
   // first create a new undo node
   automation.BeginUndo();
   try
   {
      // add a new rectangle object
      AnnRectangleObject rectObj = new AnnRectangleObject();
      rectObj.Rect = new Rect(100, 100, 200, 200);
      rectObj.Stroke = Colors.Blue;
      rectObj.Fill = Colors.Yellow;

      rectObj.StrokeThickness = 2.0;

      automation.Container.Children.Add(rectObj);

      // "select" this object
      automation.StartEditing(rectObj, false);

      // commit the undo node
      automation.EndUndo();
   }
   catch(Exception ex)
   {
      // in case of errors, cancel the undo node
      automation.CancelUndo();
      throw ex;
   }

   MessageBox.Show("Object has been added as is now selected.  Next will call //Undo// to undo the operation");
   automation.Undo();
   MessageBox.Show("Operation has been undone.  Next will call //Redo// to redo the operation");
   automation.Redo();
   MessageBox.Show("Object should be back and selected");
}
SilverlightVBCopy Code
Private Sub AnnAutomation_BeginUndo(ByVal automation As AnnAutomation)
   ' first create a new undo node
   automation.BeginUndo()
   Try
      ' add a new rectangle object
      Dim rectObj As AnnRectangleObject = New AnnRectangleObject()
      rectObj.Rect = New Rect(100, 100, 200, 200)
      rectObj.Stroke = Colors.Blue
      rectObj.Fill = Colors.Yellow

      rectObj.StrokeThickness = 2.0

      automation.Container.Children.Add(rectObj)

      ' "select" this object
      automation.StartEditing(rectObj, False)

      ' commit the undo node
      automation.EndUndo()
   Catch ex As Exception
      ' in case of errors, cancel the undo node
      automation.CancelUndo()
      Throw ex
   End Try

   MessageBox.Show("Object has been added as is now selected.  Next will call //Undo// to undo the operation")
   automation.Undo()
   MessageBox.Show("Operation has been undone.  Next will call //Redo// to redo the operation")
   automation.Redo()
   MessageBox.Show("Object should be back and selected")
End Sub

Remarks

Use this method along with the EndUndo and CancelUndo methods to programmatically add a node to the undo stack maintained by this AnnAutomation. Typically, you add an undo node as follows:

  1. Call the BeginUndo method before you make any changes to create a new node.
  2. Perform any changes to the AnnAutomation object.
  3. Call the EndUndo method to commit this undo node into the undo stack of the AnnAutomation object.
  4. In case of errors (typically in a catch statement), call the CancelUndo method to remove the node and cancel the operation.

You do not need to manually call the BeginUndo, EndUndo or CancelUndo methods when calling methods from this AnnAutomation object directly. The AnnAutomation object will internally do this for you. For example, when you call the AnnAutomation.Delete method to delete the object(s) currently being edited, the AnnAutomation object will perform the above sequence internally to add the undo node.

Use the UndoCapacity property to get or set the number of user actions that can be reversed using the Undo method, or re-applied using the Redo method. The default for the UndoCapacity property is 10 actions.

For more information, refer to Undoing WPF Automation Operations.

Requirements

Target Platforms: Silverlight 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7, MAC OS/X (Intel Only)

See Also

BeginUndo requires a Document/Medical product license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features and Unlocking Special LEAD Features.