BindingGroup.UpdateSources Metodo

Definizione

Esegue il convertitore sull'associazione e sugli ValidationRule oggetti con la ValidationStep proprietà impostata su RawProposedValue, ConvertedProposedValueo UpdatedValue e salva i valori delle destinazioni negli oggetti di origine se tutte le regole di convalida hanno esito positivo.

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

Valori restituiti

true se tutte le regole di convalida hanno esito positivo; in caso contrario, false.

Esempio

L'esempio seguente fa parte di un'applicazione che richiede all'utente di immettere più clienti e assegnare un rappresentante di vendita a ogni cliente. L'applicazione verifica che il rappresentante di vendita e il cliente appartengano alla stessa area. Nell'esempio viene chiamato UpdateSources per convalidare le associazioni e salvare i valori nell'origine se tutte le regole di convalida hanno esito positivo.

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

Commenti

Questo metodo aggiorna l'origine se ogni ValidationRule operazione riesce, ma non causa il commit delle modifiche in sospeso da parte delle origini e la fine della transazione di modifica. Ovvero, se l'oggetto di origine implementa IEditableObject. La chiamata a questo metodo non causa EndEdit la chiamata. Usare il CommitEdit metodo per fare in modo che le origini esemettano le modifiche in sospeso.

Si applica a