BindingGroup.CommitEdit 方法

定义

运行所有 ValidationRule 对象,并且在所有验证规则都成功时,更新绑定源。

public:
 bool CommitEdit();
public bool CommitEdit ();
member this.CommitEdit : unit -> bool
Public Function CommitEdit () As Boolean

返回

Boolean

如果每个 ValidationRule 都成功且将值提交到了源,则为 true;否则为 false

示例

以下示例调用 CommitEdit 保存挂起的更改,然后调用 BeginEdit 以准备要重新编辑的源。

void stackPanel1_Loaded(object sender, RoutedEventArgs e)
{
    // Set the DataContext to a PurchaseItem object.
    // The BindingGroup and Binding objects use this as
    // the source.
    stackPanel1.DataContext = new PurchaseItem();

    // Begin an edit transaction that enables
    // the object to accept or roll back changes.
    stackPanel1.BindingGroup.BeginEdit();
}
Private Sub stackPanel1_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
    ' Set the DataContext to a PurchaseItem object.
    ' The BindingGroup and Binding objects use this as
    ' the source.
    stackPanel1.DataContext = New PurchaseItem()

    ' Begin an edit transaction that enables
    ' the object to accept or roll back changes.
    stackPanel1.BindingGroup.BeginEdit()
End Sub

注解

如果每个 ValidationRule 操作都成功,此方法会导致源提交挂起的更改并结束编辑事务(如果源对象能够这样做)。

对于实现IEditableObject的每个Items对象,CommitEdit调用IEditableObject.EndEdit

适用于