0

I have a TextBox that is bind to a property underneath. It has a two way binding with custom validation. If validation doesn't pass, and there's an error, the binding doesn't update the source. How can I make it so the source is updated, even though the validation has an error? I want validation to be more of a warning, not an error.

This is my simplified xaml:

<TextBox>
    <TextBox.Text>
       <Binding Path="Value"
        UpdateSourceTrigger="PropertyChanged">
          <Binding.ValidationRules>
             <validators:TelephoneNumberRule />
             <validators:NotOptionalRule />
          </Binding.ValidationRules>
       </Binding>
    </TextBox.Text>
</TextBox>

And the property:

public string Value { get; set; }

Thanks.

mm8
  • 163,881
  • 10
  • 57
  • 88
Janjko
  • 71
  • 6

1 Answers1

1

Setting the ValidationStep property of a ValidationRule to UpdatedValue will cause it to be run after the source property has been updated:

<TextBox>
    <TextBox.Text>
        <Binding Path="Value" UpdateSourceTrigger="PropertyChanged">
            <Binding.ValidationRules>
                <validators:TelephoneNumberRule ValidationStep="UpdatedValue" />
                <validators:NotOptionalRule ValidationStep="UpdatedValue" />
            </Binding.ValidationRules>
        </Binding>
    </TextBox.Text>
</TextBox>
mm8
  • 163,881
  • 10
  • 57
  • 88
  • This is right, but this also makes the validators get a `BindingExpression` inside the value instead of a string. I solved that using this question: https://stackoverflow.com/questions/10342715/validationrule-with-validationstep-updatedvalue-is-called-with-bindingexpressi – Janjko Aug 22 '18 at 16:09