MindFusion.Scheduling for Silverlight Programmer's Guide
Undo and Redo

To enable undo and redo set the UndoEnabled property of the IProjectViewModel to true. All subsequent modifications to the project, including creation and deletion of items will be recorded in an undo history for later undo. To undo the most recent modification, call the Undo method; to redo the last undone modification, call the Redo method. To purge the undo history, either set UndoEnabled to false, or call PurgeUndoHistory method. The undo and redo function are also available as ICommand objects through the UndoCommand and RedoCommand properties.

 Note

Modifying the underlying Model will automatically reset the undo history. Therefore it is recommended that all changes to the project are performed through the ViewModel.

Composite Operations

It is possible to wrap up several modifications to the project in an atomic undo operation. To achieve this, nest all of the modification in a StartCompositeOperation/CommitCompositeOperation block. To reject all modifications in a composite block, call CancelCompositeOperation instead.

The following example creates several activities in a project and wraps them as a composite operation:

C#  Copy Code

project.StartCompositeOperation();
project.CreateActivity(null, -1).ActivityName = "test 1";
project.CreateActivity(null, -1).ActivityName = "test 2";
project.CreateActivity(null, -1).ActivityName = "test 5";
project.CommitCompositeOperation();

Visual Basic  Copy Code

project.StartCompositeOperation()
project.CreateActivity(Nothing, -1).ActivityName = "test 1"
project.CreateActivity(Nothing, -1).ActivityName = "test 2"
project.CreateActivity(Nothing, -1).ActivityName = "test 5"
project.CommitCompositeOperation()

Binding Undo/Redo Commands

Because the undo/redo operations of the project are exposed as commands (through the UndoCommand and RedoCommand properties), they can be easily bound to from various UI elements. For example, in order to bind a button in the UI to the Undo command of the project, use the following XAML code:

XAML  Copy Code

<Button Content="Undo">
  <Button.Command>
    <Binding Path="DataContext.UndoCommand" ElementName="activityView" />
  </Button.Command>
</Button>

The above code assumes that activityView identifies an ActivityChart control defined within the XAML.