Muokkaa

Jaa


Using Editing Scope

The UsingEditingScope sample demonstrates how to batch a set of changes so that they can be undone in a single atomic unit. By default, the actions taken by an activity designer author are automatically integrated into the Undo/Redo system.

Demonstrates

Editing scope and Undo and Redo.

Discussion

This sample demonstrates how to batch a set of changes to the ModelItem tree within a single unit of work. Note that when binding to ModelItem values directly from a WPF designer, changes are applied automatically. This sample demonstrates what must be done when multiple changes to be batched are being made through imperative code, rather than a single change.

In this sample, three activities are added. When editing begins, BeginEdit is called on an instance of ModelItem. Changes made to the ModelItem tree within this editing scope are batched. The BeginEdit command returns an EditingScope, which can be used to control this instance. Either OnComplete or OnRevert can be called to either commit or revert the editing scope.

You can also nest EditingScope objects, which allows for multiple sets of changes to be tracked as part of a larger editing scope and can be controlled individually. A scenario that may use this feature would be when changes from multiple dialogs must be committed or reverted separately, with all changes being treated as a single atomic operation. In this sample, the editing scopes are stacked using an ObservableCollection<T> of type ModelEditingScope. The ObservableCollection<T> is used so that the depth of the nesting can be observed on the designer surface.

To set up, build, and run the sample

  1. Build and run the sample, and then use the buttons on the left to modify the workflow.

  2. Click Open Editing Scope.

    1. This command calls BeginEdit that creates an editing scope and pushes it onto the editing stack.

    2. Three activities are then added to the selected ModelItem. Note that if the editing scope had not been opened with BeginEdit, three new activities would appear on the designer canvas. Because this operation is still pending within the EditingScope, the designer is not yet updated.

  3. Press Close Editing Scope to commit the editing scope. Three activities appear in the designer.