我有一个 WPF 数据网格。我读取了一个 csv 文件并构建了一个 ObservableCollection 对象。
我将 DataGrid.ItemsSource 设置为 Collection。然后,我想对 DataGrid 中的每一行强制执行 RowValidation。如果我,扮演用户,编辑一个单元格,RowValidation 触发,一切都很好。但是验证不会在初始加载时触发。有什么方法可以调用 ??ValidateRow??连续?在每一行?
(C#、WPF、VS2008 等)
最佳答案
对于您的绑定(bind),将 UpdateSourceTrigger 设置为属性已更改,然后将您的验证规则放入其中。默认更新源触发器是失去焦点。
<Binding Path="Name" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<ExceptionValidationRule />
</Binding.ValidationRules>
</Binding>
另外,对于另一个好的解决方案,看看这里
http://www.codeproject.com/KB/WPF/wpfvalidation.aspx
Paul 构建了一个自定义错误提供程序,例如
You can call the Validate() method on the ErrorProvider to force validation, and check if the controls are valid
关于wpf - 强制验证; WPF、数据网格、ObservableCollection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/999145/