views:

98

answers:

1

I'm using WPF and I've got an Entity bound to a series of controls. The entity is decorated with two class level validators as follows:

[ExampleValidator1, ExampleValidator2]
public class Entity

An Entity has a series of fields of which not all are always shown, dependent on the selection from combo box. A validator exists for each of these selections, if the "type" of entity does not match a particular validator that validator returns true and obviously the correct validator will validate the actual fields as follows:

public bool IsValid(object value, IConstraintValidatorContext constraintValidatorContext)
    {

        constraintValidatorContext.DisableDefaultError();
        var allPropertiesValid = true;
        var entity= (Entity)value;

        if (supplier.ParticularEntityType)
        {
            return true;
        }



        if (String.IsNullOrEmpty(entity.Name) || entity.Name.Length > 50)
        {
            constraintValidatorContext.AddInvalid<Entity, string>("must be 50 or shorter and not empty", x => x.Name);
            allPropertiesValid = false;
        }

and the XAML is as follows:

                <TextBox Grid.Row="0" Grid.Column="3">
                    <TextBox.Text>
                        <Binding Path="Entity.Name" UpdateSourceTrigger="PropertyChanged" ValidatesOnDataErrors="True">
                        </Binding>
                    </TextBox.Text>
                </TextBox>

Obviously I get the nice pretty red box and tool tips informing users of the validation requirements.

My issue is that when the selection in the combobox is changed, the red highlighting persists (becomes a small red square when a control is hidden). Could someone direct me the right way please!

A: 

Solved by firing an OnPropertyChanged when the combobox is altered, not an ideal solution but its workable.

ChrisFletcher