I have the same question as in the link below, but the answers where not satisfying for me.
ValidationRule ValidatesOnTargetUpdated NullReferenceException at Design Time
XAML
<TextBox x:Name="MyTextBox">
<TextBox.Text>
<Binding Path="MyText">
</Binding>
</TextBox.Text>
</TextBox>
Code-Behind
Binding binding = BindingOperations.GetBinding(MyTextBox, TextBox.TextProperty);
binding?.ValidationRules.Add(new MyValidationRule()
{
ValidatesOnTargetUpdated = true
});
It works with this section in code behind. But I am looking for a only XAML solution, because it is more intuitive and for me better maintainable. Does anybody have an idea?
I found a "solution" (or more a workaround) on my own. The designer works for me if I change ValidatesOnTargetUpdated to ValidationStep with the wished value.
Attention: For example, the TextBox behaves differently if you put in ValidationStep="UpdatedValue" and ValidationStep="ConvertedProposedValue". More information on ValidationRule with ValidationStep="UpdatedValue" is called with BindingExpression instead of updated value.
However, I could not find why ValidatesOnTargetUpdated did not work.