1

我想在 AutoGeneratingColumn 事件中执行此操作:

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

可能吗?这些列是自动生成的,所以我只想将 ValidationRules 添加到 Binding。

4

1 回答 1

2

我结束了这个,如果没有人有更好的解决方案。

private void DataGridAutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
    var binding = (Binding)((DataGridBoundColumn)e.Column).Binding;
    binding.ValidationRules.Add(new DataRowValidationRule { ValidationStep = ValidationStep.UpdatedValue });
}
于 2009-10-15T07:37:22.203 回答