Datagrid:停止/取消 AddNew 或 EditItem 事务?
我使用数据网格来显示用户可以在图像上创建的“选择矩形”的坐标。
我使用数据网格的数据绑定到可观察的集合,因为其他目的也需要坐标。
因此,当用户创建一个新的 Rectangle 时,一个新条目将添加到 Observable 集合中。
要直接在数据网格中显示新矩形的坐标,我必须调用“myDatagrid.Items.Refresh()”。
现在的问题是,在某些情况下,程序会因“无效操作异常”而失败,这表明“当数据网格上的 AddNew 或 EditItem - 事务”正在运行时,无法完成 Refresh()。
我不确切知道这个事务是在哪里触发的,但我观察到只有当鼠标光标在数据网格的一个单元格中处于活动状态时,当调用 Refresh() 时,才会发生异常。
因此,可能会有一些真正对我有帮助的提示:
- 如何“手动”取消数据网格所有单元格的编辑模式? (当然我已经尝试过 DataGrid.CancelEdit() 和 DataGrid.CommitEdit(),但这没有帮助)
- 什么是 EditItem-Transaction / AddItem-Transaction 或者如何停止它运行?
- 任何其他在不使用 DataGrid.Refresh() 的情况下安全更新绑定的想法..
I use a datagrid to show coordinates of "selection rectangles" that the user can create on an image.
I use databinding of the data grid to an observable collection, since the coordinates are also needed for other purposes.
So, when the user creates a new Rectangle, an new entry is added to the Observable collection.
To directly display the coordinates of the new rectangle in the datagrid i have to call "myDatagrid.Items.Refresh()".
The problem is now, that in some cases, the program fails with an "Invalid Operation Exception", that says the Refresh() can not be done "while an AddNew or EditItem - Transaction" on the datagrid is running.
I don't know exactly, where this Transactions are triggered, but i observes that the exception only occurs, when the Mouse-Courser was active in one cell of the datagrid at the moment, when the Refresh() is called.
So there would be some possible hints that would really help me:
- How can I 'manually' cancel the Edit-Mode for all cells of the datagrid?
(of course I have tried the DataGrid.CancelEdit() and DataGrid.CommitEdit(), but that doesn't help) - What is an EditItem-Transaction / AddItem-Transaction or how can I stop it running?
- Any other ideas to safely update the binding without using DataGrid.Refresh()..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论