DataGrid 验证。未调用错误
当 SelectedItem.DT 抛出错误时 Validation_Error 未被调用? DT 是来自 SQL 查询的数据表,我想在 TSQL 失败时显示 SQL 错误。我想我可以构建一个数据表并将 ex.msg 放入表中。但我宁愿调用 Validation_Error。
<DataGrid Grid.Row="1" Grid.Column="0" AutoGenerateColumns="True"
ItemsSource="{Binding ElementName=cbReports, Path=SelectedItem.DT, ValidatesOnExceptions=True, NotifyOnValidationError=True, NotifyOnSourceUpdated=True}"
Validation.Error="Validataion_Error" />
当集合中抛出错误时,此文本框(在另一页上)确实会调用 Validation_Error 。
<TextBox Text="{Binding Path=DF.FieldValue, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}"
Validation.Error="Validataion_Error"/>
When SelectedItem.DT throws an error Validation_Error is not called? DT is a DataTable from a SQL query and I want to display the SQL error if the TSQL fails. I guess I could build a DataTable and put the ex.msg in the table. But I would rather call Validation_Error.
<DataGrid Grid.Row="1" Grid.Column="0" AutoGenerateColumns="True"
ItemsSource="{Binding ElementName=cbReports, Path=SelectedItem.DT, ValidatesOnExceptions=True, NotifyOnValidationError=True, NotifyOnSourceUpdated=True}"
Validation.Error="Validataion_Error" />
This TextBox (on another page) does call Validation_Error when an error is thrown in set.
<TextBox Text="{Binding Path=DF.FieldValue, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}"
Validation.Error="Validataion_Error"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DataTable 未实现 IDataErrorInfo 那么它不会自动为您执行任何验证错误。我总是将 DataTable 转换为实现 IDataErrorInfo 的类的 ObservableCollection 。
我猜你的文本框绑定起作用的原因是
DF.FieldValue
中的DF
实现了IDataErrorInfo
。DataTable is not implement IDataErrorInfo then it isn't do any validation error automatically for you. I always transform DataTable to ObservableCollection of my class that implement IDataErrorInfo.
I guess that the reason your textbox binding works is
DF
in yourDF.FieldValue
is implementIDataErrorInfo
.