ModelEditingScope 类
更新:2007 年 11 月
表示对编辑存储区的一组更改。
命名空间: Microsoft.Windows.Design.Model
程序集: Microsoft.Windows.Design.Interaction(在 Microsoft.Windows.Design.Interaction.dll 中)
语法
声明
Public MustInherit Class ModelEditingScope _
Implements IDisposable
用法
Dim instance As ModelEditingScope
public abstract class ModelEditingScope : IDisposable
public ref class ModelEditingScope abstract : IDisposable
public abstract class ModelEditingScope implements IDisposable
备注
更改组是事务性的。可以将在一个编辑范围内所做的更改作为一个单元提交或中止。
编辑范围提交后,编辑存储区将采用其中发生的所有更改,并将这些更改应用于模型。在调用 Complete 方法之前,如果调用了编辑范围的 Revert 方法或释放了编辑范围,则该编辑范围将改为反转对基础对象所做的更改,并会从编辑存储区中重新应用状态。这为撤消机制奠定了坚实的基础。
请始终将编辑范围包装在 using 语句或 try/finally 块中。如果引发了异常,则在对 Dispose 方法的调用中将中止所做的更改。
示例
' 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; }
}
继承层次结构
System.Object
Microsoft.Windows.Design.Model.ModelEditingScope
线程安全
此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。
另请参见
参考
Microsoft.Windows.Design.Model 命名空间