views:

453

answers:

1

I want to do this in the AutoGeneratingColumn event:

<my:DataGridTextColumn Header="CompanyName">
    <my:DataGridTextColumn.Binding>
        <Binding Path="CompanyName">
            <Binding.ValidationRules>
                <local:DataRowValidation ValidationStep="UpdatedValue" />
            </Binding.ValidationRules>
        </Binding>
    </my:DataGridTextColumn.Binding>
</my:DataGridTextColumn>

Is it possible? The columns are autogenerated so I just want to add the ValidationRules to Binding.

A: 

I ended up with this, if no one has any better solution.

private void DataGridAutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
    var binding = (Binding)((DataGridBoundColumn)e.Column).Binding;
    binding.ValidationRules.Add(new DataRowValidationRule { ValidationStep = ValidationStep.UpdatedValue });
}
Jostein