Share via


ModelEditingScope Class

Represents a group of changes to the editing store.

Inheritance Hierarchy

System.Object
  Microsoft.Windows.Design.Model.ModelEditingScope

Namespace:  Microsoft.Windows.Design.Model
Assembly:  Microsoft.Windows.Design.Interaction (in Microsoft.Windows.Design.Interaction.dll)

Syntax

'Declaration
Public MustInherit Class ModelEditingScope _
    Implements IDisposable
public abstract class ModelEditingScope : IDisposable
public ref class ModelEditingScope abstract : IDisposable
[<AbstractClass>]
type ModelEditingScope =  
    class
        interface IDisposable
    end
public abstract class ModelEditingScope implements IDisposable

The ModelEditingScope type exposes the following members.

Constructors

  Name Description
Protected method ModelEditingScope Initializes a new instance of the ModelEditingScope class.

Top

Properties

  Name Description
Public property Description Gets or sets a description for the group.

Top

Methods

  Name Description
Protected method CanComplete Determines whether the OnComplete method can be called, or whether the change should instead be reverted.
Public method Complete Completes the editing scope.
Public method Dispose() Releases all resources used by the ModelEditingScope.
Protected method Dispose(Boolean) Releases the unmanaged resources used by the ModelEditingScope class and optionally releases the managed resources.
Public method Equals Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Called during finalization to abort the group. (Overrides Object.Finalize().)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Protected method OnComplete Performs the actual complete of the editing scope.
Protected method OnRevert Performs the actual revert of the editing scope.
Public method Revert Abandons the changes that were made during the editing scope.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Public method Update Performs a synchronous refresh of the view.

Top

Remarks

Change groups are transactional. Changes that are made under an editing scope can be committed or aborted as a unit.

When an editing scope is committed, the editing store takes all changes that occurred in it and applies them to the model. If the editing scope’s Revert method is called, or the editing scope is disposed before the Complete method is called, the editing scope will instead reverse the changes that were made to the underlying objects, reapplying state from the editing store. This provides a solid basis for an undo mechanism.

Always wrap editing scopes in using statements or try/finally blocks. If an exception is raised, the change is aborted in the call to the Dispose method.

Examples

' The SetHeightAndWidth utility method sets the Height and Width
' properties through the model and commits the change.
Private Sub SetHeightAndWidth(ByVal [auto] As Boolean) 

    settingProperties = True

    Dim batchedChange As ModelEditingScope = adornedControlModel.BeginEdit()
    Try
        Dim widthProperty As ModelProperty = adornedControlModel.Properties("Width")

        Dim heightProperty As ModelProperty = adornedControlModel.Properties("Height")

        If [auto] Then
            widthProperty.ClearValue()
            heightProperty.ClearValue()
        Else
            widthProperty.SetValue(20.0)
            heightProperty.SetValue(20.0)
        End If

        batchedChange.Complete()
    Finally
        batchedChange.Dispose()
        settingProperties = False
    End Try

End Sub
// The SetHeightAndWidth utility method sets the Height and Width
// properties through the model and commits the change.
private void SetHeightAndWidth(bool autoSize)
{
    settingProperties = true;

    try
    {
    using (ModelEditingScope batchedChange = adornedControlModel.BeginEdit())
    {
        ModelProperty widthProperty =
            adornedControlModel.Properties["Width"];

        ModelProperty heightProperty =
            adornedControlModel.Properties["Height"];

        if (autoSize)
        {
            widthProperty.ClearValue();
            heightProperty.ClearValue();
        }
        else
        {
            widthProperty.SetValue(20d);
            heightProperty.SetValue(20d);
        }

        batchedChange.Complete();
    }
    }
    finally { settingProperties = false; }
}

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

Microsoft.Windows.Design.Model Namespace

Other Resources

Walkthrough: Creating a Design-time Adorner

WPF Designer Extensibility