Hello all,
The WPF data binding model allows associating ValidationRules with Binding object.
Into my XamDataGrid, each field has defined a set of ValidationRules
( business rules. These classes are derived from ValidationRule and can make a lot of validation, for example have methods to interrogate a database for process of validation).
My grid is bounded to an IEnumerable property.
How can I reuse my set of validation business rules on each field?
I seen that for a ValueEditor there is a ValueConstraint property, but this is not usefully for me.
There is, also a ValidateCurrentValue method. Can I override this to apply my business rules? And if yes, how can I do this?
If no, someone knows if a field value is bounded, somehow, to a property using Binding object? In this case I can add my validation rules
to Binding.ValidationRules collection.
I ask this because I see that in XamDataGrid you can add Unbound fields. Have these 2 things something in common?
Can somebody help me?
Best Regards, Liviu
I am using your example in a XamNumericEditor (WPF v8.2), I have a Mask -nnn.nnn and Rules check min and max values. (-2.000 & +2.000 )
I can get my ValidateCurrentValue to return false and an exception but the XmlNumericEditor still allows the characters to be entered.
Is this expected ? how can I work around it?
thanks
Martin
Nice example,
One question though: If you have several different editors, do you have to duplicate all this code? If i could get a hold on the Binding Object I could easily attach my ValidationRules without inheriting every single Editor component.
/Carl
Sandeep,
we are evaluating xamdatagrid for wpf & examining this sample.
why do we need Infragistics2.Shared.v8.1, Infragistics2.Win.UntraWinDataSoruce.v8.1, Infragistics2.Win.v8.1 for xamdatagrid for wpf.
where do i get these files, if it is required?
vairam
And here's the sample that I meant to attach to the previous post.
Hi Liviu,
ValidateCurrentValue is virtual and so you can override to apply your own validation logic. I've attached a sample that does this. It basically derives a MyTextEditor from XamTextEditor and sets the EditorType of the field settings to that derived type. It also sets the EditorStyle of the field settings to a style that sets the validation rules on MyTextEditor. ValidationRules are set on the editor using dynamic resource (data grids Resources collection) via the editor's style.
Hope this helps,
Sandip