簡體   English   中英

檢查任何 WPF DataGrid 單元格是否有錯誤

[英]Checking If Any WPF DataGrid Cell Has Error

我在單元格上設置了驗證,它按預期工作(在文本框周圍放置一個紅色突出顯示並添加帶有錯誤的工具提示)。 但是,如果我嘗試訪問 TheGrid 是我的 DataGrid 的 Validation.GetHasError(TheGrid),它總是錯誤的。 有誰知道如何檢查 DataGrid 中的任何單元格是否有錯誤?

我想這樣做,以便在出現錯誤時禁用保存。

您可能會遇到虛擬化問題,但您可能必須查看容器:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM