Validate datagrid values through enterprise library Configuration file

Topics: Enterprise Library Core, Validation Application Block
Jun 14, 2011 at 6:01 AM

I am working on WPF with MVVM design pattern doing all the validations through Enterprise Library using configuration file.

I want to validate my grid cell values through enterprise library configuration file.In my view model I have an observable collection property that is bound to the datagrid in a view. Then,I want to validate one of my cell value for range validation using enterprise library..But I am not finding any proper way to do the same.I don't want to use any custom validator rather want to achieve with the enterprise library configuration file only.

Actually while adding a validation to datagrid column we are binding like:-

<xa:ValidatorRule RulesetName="NameOfRuleset" SourceType="{x:Type vm:ViewModelType}" SourcePropertyName="NameOfProperty" ValidationSpecificationSource="Configuration" ValidatesOnTargetUpdated="True" /> 

But as in this case my view model will not have a property specifically for this field rather it has collection,so i am stucked on how to do the same, Can anyone please guide me how to achieve the same.Please let me know if my explanation is not clear enough.

Jun 14, 2011 at 6:40 PM

Please let me know if my understanding is correct, is what you mean is that your "NameOfProperty" SourceProperty is a collection type property? If yes, would you think using Object Collection Validator would help you with your problem or am I getting it wrong. Please let me know.

Gino Terrado
Global Technologies and Solutions
Avanade, Inc.

Jun 15, 2011 at 4:20 AM

Thanks for the reply.

Yes you are right.My source property is a collection type property.Its a collection of Employee object.Inside Employee I have a property say Salary.I want to validate the range of the salary.

My View model has a collection of Employees & my datagrid is bound to this collection.Now I want to validate for salary column.Employee is coming from Entity framework.

I want to achieve it with the configuration file only without using any custom validator.Is it possible with Object Collection Validator?

Please let me know on how to achieve this because I am not finding an exact way of doing this.

Thanks for the support.

Jun 15, 2011 at 4:41 PM


Please see if this related thread would help Also the documentation is also helpful on understanding the ObjectCollectionValidator different Properties available.

Basically in the config, what you simply need is to simply select the property you want to validate and assign an ObjectCollectionValidator to it.  Select the appropriate type for the TargetType property of the ObjectCollectionValidator and etc...

Hope this helps,

Gino Terrado
Global Technologies and Solutions
Avanade, Inc.