How can I use WPF + Enterprise Lib Validation block using Config file?
Using MS Enterprise Libs, I like to define my Validation Rules in
App.Config (using Enterprise Library Configuration) and hook them to text
boxes on my WPF GUI.
To make it more clear consider this scenario:
In my test WPF project, I have defined this validation over a property of
my Person object and implemented IDataErrorInfo.
[StringLengthValidator(1, 5, MessageTemplate = "String was too long.")]
public string LastName { get; set; }
In the view, that property is bind to a text box:
<TextBox
Name="txtLastName"
Style="{StaticResource textBoxInError}"
Grid.Column="1" Grid.Row="1" Margin="5">
<Binding Path="LastName" UpdateSourceTrigger="LostFocus">
<Binding.ValidationRules>
<vab:ValidatorRule
SourceType="{x:Type local:Person}"
SourcePropertyName="LastName"/>
</Binding.ValidationRules>
</Binding>
</TextBox>
Everything works fine and you see the error when you leave the text box.
But as I said, I want to define my validation rules in a config file and I
like them to be trigger automatically whenever there is a PropertyChange
instead of me defining a Validator and validate the person object.
Thank you for your help
No comments:
Post a Comment