Search
UndoManager.StartComposite Method (String)
See Also
 





Creates an 'active' composite record with the specified title.

Namespace: MindFusion.Diagramming.Wpf
Assembly: MindFusion.Diagramming.Wpf

 Syntax

C#  Copy Code

public CompositeCmd StartComposite (
    string title
)

Visual Basic  Copy Code

Public Function StartComposite( _
    title As String _
) As CompositeCmd

 Parameters

title
A string to be associated with the composite record. It can be used later to give more information to users what exactly will be undone or redone. Use the Title property of the command class to get the title of an action record.

 Return Value

An instance of the CompositeCmd class which represents the active composite record. Call its Execute method when done with recording actions in the composite.

 Remarks

Sometimes several actions must be represented as a single atomic operation. That can be achieved by using composites, represented by the CompositeCmd class. However actions records that are implicitly created by WpfDiagram as a response to users actions or method calls cannot be added directly to a composite. The StartComposite method creates an 'active' composite, to which implicitly created records are added automatically. Call the composite's Execute method to stop adding action records to it and save it in the command history. Calling Undo or Redo for the composite record, undoes or redoes all actions contained within it.

 Example

The following example illustrates how to create composite commands:

C#  Copy Code

// Implicitly created undo records will be saved here
CompositeCmd composite = diagram.UndoManager.StartComposite("Create group");

// Call methods that create undo records
ShapeNode node1 = diagram.Factory.CreateShapeNode(0, 0, 30, 30);
ShapeNode node2 = diagram.Factory.CreateShapeNode(0, 0, 15, 15);
Group g = diagram.Factory.CreateGroup(node1);
g.AttachToCorner(node2, 0);

// This goes to the active composite too
ChangeItemCmd change = new ChangeItemCmd(node2, "");
node2.Locked = true;
change.Execute();

// Save the active composite in history
composite.Execute();

Visual Basic  Copy Code

' Implicitly created undo records will be saved here
Dim composite As CompositeCmd = diagram.UndoManager.StartComposite("Create group")

' Call methods that create undo records
Dim node1 As ShapeNode = diagram.Factory.CreateShapeNode(0, 0, 30, 30)
Dim node2 As ShapeNode = diagram.Factory.CreateShapeNode(0, 0, 15, 15)
Dim g As Group = diagram.Factory.CreateGroup(node1)
g.AttachToCorner(node2, 0)

' This goes to the active composite too
Dim change As ChangeItemCmd = New ChangeItemCmd(node2, "")
node2.Locked = True
change.Execute()

' Save the active composite in history
composite.Execute()

 See Also