[英]Checking If Any WPF DataGrid Cell Has Error
I have validation set up on the cells and it works as expected (placing a red highlight around the textbox and adding a tooltip with the error).我在单元格上设置了验证,它按预期工作(在文本框周围放置一个红色突出显示并添加带有错误的工具提示)。 However, If I try to access Validation.GetHasError(TheGrid) where TheGrid is my DataGrid, it is always false.
但是,如果我尝试访问 TheGrid 是我的 DataGrid 的 Validation.GetHasError(TheGrid),它总是错误的。 Does anyone know how to check if ANY cells in the DataGrid have errors?
有谁知道如何检查 DataGrid 中的任何单元格是否有错误?
I want to do this so I can disable saving if there are errors.我想这样做,以便在出现错误时禁用保存。
You might run into problems with virtualization with this but you probably do have to look at the containers:您可能会遇到虚拟化问题,但您可能必须查看容器:
var errors = (from c in
(from object i in _myGrid.ItemsSource
select _myGrid.ItemContainerGenerator.ContainerFromItem(i))
where c != null
select Validation.GetHasError(c))
.FirstOrDefault(x => x);
if (errors)
{
//There be errors
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.