WPF Validation with Entlib 5.0 on non text properties
I am trying to validate user input in WPF with Entlib 5.0. I want to check if value in textbox is a number.
My model:
public class Customer
{
[Required(ErrorMessage = "Country is required")]
public double Country { get; set; }
}
Xaml:
<TextBox>
<TextBox.Text>
<Binding Path="Country" UpdateSourceTrigger="PropertyChanged" >
<Binding.ValidationRules>
<vab:ValidatorRule ValidationSpecificationSource="All" SourceType="{x:Type bl:Customer}" SourcePropertyName="Country"/>
开发者_如何学C </Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
When I am setting the text to texbox Validation.HasError is set to false.
Any ideas how I can validate this situation.
I've found the solution.
Binding should looks like this:
<Binding Path="Country" UpdateSourceTrigger="PropertyChanged" NotifyOnValidationError="True" ValidatesOnExceptions="True">
<Binding.ValidationRules>
<vab:ValidatorRule ValidationSpecificationSource="All" SourceType="{x:Type bl:Customer}" SourcePropertyName="Country"/>
</Binding.ValidationRules>
</Binding>
精彩评论