BindingGroup.UpdateSources Метод

Определение

Выполняет преобразователь для привязки и объектов ValidationRule, у которых свойство ValidationStep имеет значение RawProposedValue, ConvertedProposedValue или UpdatedValue, и сохраняет значения целевых объектов в исходных объектах, если все правила проверки выполнены успешно.

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

Возвращаемое значение

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 Используйте метод, чтобы источники зафиксировали ожидающие изменения.

Применяется к