关于DataGrid数据验证显示的问题
我的Reference.cs文件里的字段如下:
- C# code
[Required(ErrorMessage = "调度数量必填!")] [System.Runtime.Serialization.DataMemberAttribute(IsRequired=true, Order=66)] public System.Nullable<double> 调度数量 { get { return this.调度数量Field; } set { if (value <= this.订单数 - 调度总数 ) { Validator.ValidateProperty(value, new ValidationContext(this, null, null) { MemberName = "调度数量" }); if ((this.调度数量Field.Equals(value) != true)) { this.调度数量Field = value; this.RaisePropertyChanged("调度数量"); } } else { throw new System.Exception("调度数量不合法!"); } } }判断里两个参数获取都没问题,当Value大于了this.订单数 - 调度总数之后,DataGrid不接受这个值,但是也没有在下方显示这个错误,也就是说 throw new System.Exception("调度数量不合法!");没有反应,怎么才能让这个错误提示放在DataGrid的下面呢?
[解决办法]
这种写法应是没有问题的,
不知楼主在 DataGridTextColumn 中的 Binding 是怎么写的,不妨加上一个 Converter 试试,这个 Converter 就只返回 value 本身,不作任何操作就可以。
正常情况,是会在单元格的右上方出现红色三角,弹出红色异常框框, DataGrid 内部的 ValidationSummary 也显示这一异常