Using Editing Scope

.NET Framework (current version)

This 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.

Editing scope and Undo and Redo.

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.

  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.

System_CAPS_ICON_important.jpg Important

The samples may already be installed on your machine. Check for the following (default) directory before continuing.


If this directory does not exist, go to Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) Samples for .NET Framework 4 to download all Windows Communication Foundation (WCF) and WF samples. This sample is located in the following directory.