views:

12

answers:

0

I'm having a problem with validation rules not firing when the initial value that they are bound to is null.

For example I have this DataGridTextColumn that is in a DataGrid that has CanUserAddRows set to true.

<DataGridTextColumn Header="Supplier Ref" Width="*">
<DataGridTextColumn.Binding>
    <Binding Path="SupplierRef" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" NotifyOnValidationError="True" >
        <Binding.ValidationRules>
            <SomeNameSpace:SupplierRefValidator MaxLength="20"/>
                </Binding.ValidationRules>
            </Binding>
</DataGridTextColumn.Binding>

When the user adds a new row the initial value the SupplierRef is bound to is null, the seems to mean that validator never fires or is ignored.

I've tried setting ValidatesOnTargetUpdated="True", but this means as soon as a new row is added to the grid the validator gets fired, meaning an error/warning is displayed before the user has typed anything.

Is there a way around this problem?

Thanks for any help in advance.