BindingGroup.CommitEdit 方法

定義

如果所有驗證規則都成功,這個方法會執行所有的 ValidationRule 物件,並更新繫結來源。Runs all the ValidationRule objects and updates the binding sources if all validation rules succeed.

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

傳回

如果每一個 ValidationRule 都成功,而且這些值都被認可到來源,則為 true,否則為 falsetrue if every ValidationRule succeeds and the values are committed to the sources; otherwise, false.

範例

下列範例會呼叫CommitEdit來儲存暫止的變更,然後BeginEdit呼叫來準備要重新編輯的來源。The following example calls CommitEdit to save the pending changes and then calls BeginEdit to prepare the source to be re-edited.

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如果成功,這個方法會使來源認可暫止的變更,並在來源物件能夠執行這項作業時結束編輯交易。If every ValidationRule succeeds, this method causes the sources to commit the pending changes and end the edit transaction, if a source object is capable of doing so.

針對中Items CommitEdit的每個物件,呼叫IEditableObjectIEditableObject.EndEditFor each object in Items that implements IEditableObject, CommitEdit calls IEditableObject.EndEdit

適用於