BindingGroup.UpdateSources Метод

Определение

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

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