验证失败时出现DataGrid异常(不允许使用DeferRefresh ...) [英] DataGrid exception on validation failure (DeferRefresh is not allowed...)

查看:142
本文介绍了验证失败时出现DataGrid异常(不允许使用DeferRefresh ...)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DataGrid验证方案问题

In the same series as the DataGrid validation scheme issues , I get an exception when

  • 单元格无效
  • DataContext更改

这发生在绑定到CollectionViewSource的DataGrid中.此CVS本身具有绑定到ListBox当前选定产品的DataContext.因此,我们正在编辑产品的详细信息,这些详细信息包括DataGrid(DataGridTextColumn)中的数据列表. 在这种情况下).

This happens in a DataGrid, which is bound to a CollectionViewSource. This CVS itself has a DataContext bound to the currently selected product of a ListBox. So we are editing the details of product, those details include a data list in a DataGrid (DataGridTextColumn in this case).

通过使用实现IDataErrorInfo的数据类型或通过ValidationRule,如果验证失败,则DataGrid会通过保留TextBox并在其周围显示一个红色框来做出反应(当验证正常时,单元格将转换回一个 TextBlock).

Either by using a data type that implements IDataErrorInfo or by using a ValidationRule, if the validation fails the DataGrid reacts by keeping the TextBox and showing a red box around it (when the validation is OK, the cell is tranformed back to a TextBlock).

没有什么可以阻止我选择其他产品.然后,DataGrid显示新数据,一切正常.但是,如果我返回验证失败的产品,则会收到此异常:

Nothing prevents me from selecting another product. The DataGrid then shows the new data and everything is fine. But if I come back to the product which failed validation, I get this exception:

InvalidOperationException,在AddNew或EditItem事务期间不允许使用'DeferRefresh'.

如何防止这种情况?选择其他产品或DataContext更改后,取消对该故障单元格上的编辑的正确方法是什么?

How can I prevent that? What is the correct way of cancelling the edit on that faulty cell when another product is selected, or when the DataContext changes?

我可以检测到那些事件,但是CancelEdit()在DataGrid上不起作用(无结果).

I can detect those events, but CancelEdit() doesn't work on the DataGrid (no result).

我正在使用.NET 4.

I'm using .NET 4.

 

可以在此处查看代码: C#部分 XAML部分.可以下载代码 从此处.

The code can be viewed here: C# part , XAML part . The code can be downloaded from here .

推荐答案

问题报告给 MS反馈(适用于任何有兴趣的人).
Problem reported to MS feedback (for anyone interested).


这篇关于验证失败时出现DataGrid异常(不允许使用DeferRefresh ...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆