我想在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。
答案 0 :(得分:2)
如果没有人有更好的解决方案,我最终会这样做。
private void DataGridAutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
var binding = (Binding)((DataGridBoundColumn)e.Column).Binding;
binding.ValidationRules.Add(new DataRowValidationRule { ValidationStep = ValidationStep.UpdatedValue });
}