BindingGroup.UpdateSources メソッド

定義

ValidationRule プロパティが ValidationStepRawProposedValue、またはConvertedProposedValueに設定されているバインディングおよびUpdatedValue オブジェクトに対してコンバーターを実行し、すべての検証規則が成功した場合にターゲットの値をソース オブジェクトに保存します。

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

返品

true すべての検証規則が成功した場合。それ以外の場合は false

次の例は、複数の顧客を入力し、各顧客に営業担当者を割り当てるようユーザーに求めるアプリケーションの一部です。 アプリケーションは、営業担当者と顧客が同じリージョンに属していることを確認します。 この例では、 UpdateSources を呼び出してバインディングを検証し、すべての検証規則が成功した場合に値をソースに保存します。

void saveCustomer_Click(object sender, RoutedEventArgs e)
{
    Button btn = sender as Button;
    FrameworkElement container = (FrameworkElement) customerList.ContainerFromElement(btn);

    // If the user is trying to change an items, when another item has an error,
    // display a message and cancel the currently edited item.
    if (bindingGroupInError != null && bindingGroupInError != container.BindingGroup)
    {
        MessageBox.Show("Please correct the data in error before changing another customer");
        container.BindingGroup.CancelEdit();
        return;
    }

    if (container.BindingGroup.UpdateSources())
    {
        bindingGroupInError = null;
        MessageBox.Show("Item Saved");
    }
    else
    {
        bindingGroupInError = container.BindingGroup;
    }
}
Private Sub saveCustomer_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    Dim btn As Button = TryCast(sender, Button)
    Dim container As FrameworkElement = CType(customerList.ContainerFromElement(btn), FrameworkElement)

    ' If the user is trying to change an items, when another item has an error,
    ' display a message and cancel the currently edited item.
    If bindingGroupInError IsNot Nothing AndAlso bindingGroupInError IsNot container.BindingGroup Then
        MessageBox.Show("Please correct the data in error before changing another customer")
        container.BindingGroup.CancelEdit()
        Return
    End If

    If container.BindingGroup.UpdateSources() Then
        bindingGroupInError = Nothing
        MessageBox.Show("Item Saved")
    Else
        bindingGroupInError = container.BindingGroup
    End If

End Sub

注釈

このメソッドは、すべての ValidationRule が成功した場合にソースを更新しますが、ソースが保留中の変更をコミットして編集トランザクションを終了することはありません。 つまり、ソース オブジェクトが IEditableObjectを実装している場合です。 このメソッドを呼び出しても、 EndEdit は呼び出されません。 CommitEditメソッドを使用して、ソースに保留中の変更をコミットさせます。

適用対象