ModelEditingScope Class
Represents a group of changes to the editing store.
Namespace: Microsoft.Windows.Design.Model
Assembly: Microsoft.Windows.Design.Interaction (in Microsoft.Windows.Design.Interaction.dll)
Syntax
'Declaration
Public MustInherit Class ModelEditingScope _
Implements IDisposable
'Usage
Dim instance As ModelEditingScope
public abstract class ModelEditingScope : IDisposable
public ref class ModelEditingScope abstract : IDisposable
public abstract class ModelEditingScope implements IDisposable
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(Control.WidthProperty)
Dim heightProperty As ModelProperty = adornedControlModel.Properties(Control.HeightProperty)
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[Control.WidthProperty];
ModelProperty heightProperty =
adornedControlModel.Properties[Control.HeightProperty];
if (autoSize)
{
widthProperty.ClearValue();
heightProperty.ClearValue();
}
else
{
widthProperty.SetValue(20d);
heightProperty.SetValue(20d);
}
batchedChange.Complete();
}
}
finally { settingProperties = false; }
}
Inheritance Hierarchy
System.Object
Microsoft.Windows.Design.Model.ModelEditingScope
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