views:

42

answers:

1

Hi there,

i have a validation rule like so:

public class MyRule : ValidationRule
{

    public override ValidationResult Validate(object value, CultureInfo cultureInfo)
    {
        if ((int)value < 0)
        {
            return new ValidationResult("Error, value must be > 0");
        }
        else
        {
            return ValidationResult.Success;
        }
    }
}

How can I apply this to a column in a DataGrid so what it's fired when the DataGrid is bound, not just when the user changes the cell. My column

            <data:DataGridTextColumn Header="BookSize" Binding="{Binding BookSize.Value}" >

            </data:DataGridTextColumn>
A: 

In your MetaData class where your BookSize property is included, add the attribute:

[CustomValidation(typeof(MyRule), "MyRuleValidation",
                  ErrorMessage = "Your Error Message")]
public int BookSize;

I'm guessing at int, but it should give you a good idea of where to put it.

Ardman