BindingGroup.UpdateSources Metoda

Definice

Spustí převaděč na vazbě a ValidationRule objekty, které mají ValidationStep vlastnost nastavena na RawProposedValue, ConvertedProposedValuenebo UpdatedValue a uloží hodnoty cílů do zdrojových objektů, pokud jsou všechna ověřovací pravidla úspěšná.

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

Návraty

truepokud jsou všechna ověřovací pravidla úspěšná; v opačném případě . false

Příklady

Následující příklad je součástí aplikace, která uživatele vyzve k zadání více zákazníků a každému zákazníkovi přiřadí zástupce prodeje. Aplikace zkontroluje, že obchodní zástupce a zákazník patří do stejné oblasti. Příklad volání UpdateSources pro ověření vazeb a uložení hodnot do zdroje, pokud jsou všechna ověřovací pravidla úspěšná.

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

Poznámky

Tato metoda aktualizuje zdroj, pokud je každý ValidationRule úspěšný, ale nezpůsobí, že zdroje potvrdí čekající změny a ukončí transakci úprav. To znamená, že pokud zdrojový objekt implementuje IEditableObject. Volání této metody nezpůsobí EndEdit volání. CommitEdit Pomocí této metody můžete zdroje potvrdit čekající změny.

Platí pro