Reputation: 1215
I have a ValidationRule on a Text Box. When the ValidationResult returns true, this fires the set on the property that the text box is bound to.
When the ValidationResult returns false, the set is not fired.
Any pointers as to why its not firing, and how to solve it, greatly appreciated.
Thanks
Joe
Here is the XAML of the Text Box :
<Binding Path="CorrectEntry" UpdateSourceTrigger="PropertyChanged" NotifyOnValidationError="True" >
<Binding.ValidationRules>
<localValidation:CorrectEntryValidationRule x:Name="validator" ValidatesOnTargetUpdated="True"> <localValidation:CorrectEntryValidationRule.RangeContainer>
<localValidation:CorrectEntryRangeContainer
DataContext="{Binding
Source={StaticResource DataContextBridge},
Path=DataContext}"
Min="{Binding Lower}"
Max="{Binding Upper}"
/>
</localValidation:CorrectEntryValidationRule.RangeContainer>
</localValidation:CorrectEntryValidationRule>
</Binding.ValidationRules>
</Binding>
Upvotes: 0
Views: 189
Reputation: 228
See the documentation for Validation Rule. it is by design that the property don't get set when Validation Rule returns false.
You should not use Validation Rule, if you want your Propery to be set. You should inherit your class from IDataErrorInfo. And implement the 2 methods from that interface.
Upvotes: 2
Reputation: 184947
This is the normal and usually wanted behavior, if your data is invalid you don't want it to be saved in your model.
(If you want to do validation via exceptions thrown in the setter you can use a property on the binding)
Upvotes: 1