MVVM将DataGrid(WPF工具包)绑定到DataTable
我在我的项目中使用 MVVM,设置到 DataTable 的绑定第一次工作正常,但是当我更新 DataTable 上的数据后,它似乎对 DataGrid 没有影响。有人知道如何解决吗?
I use MVVM for my project, the binding that set to DataTable work correctly at first time, but after I have update data on DataTable, it seem don't effect on DataGrid. Anyone know how to solving it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果没有更多信息和一些代码,很难说(我没有使用 WPF Toolkit 网格 - 我使用 Infragistics 网格。)有几件事:
您是否通知 UI 属性更改(通过实现 INotifyPropertyChanged)接口)?
您说“在更新 DataTable 上的数据之后”。怎么更新了?通过网格,还是通过其他方式?您的 MVVM 类是否正确“刷新”(并因此通知 datagrid/UI 数据已更改)?
我在这件事上有不同的运气。有时,如果我以编程方式向集合添加元素,Infragistics 网格不会更新。我几乎必须重新阅读整个内容才能更新网格。我还没找到原因。也许您正在处理类似的“异常”。
抱歉,不一定有帮助,但也许足以为您指明正确的方向...如果没有更多信息,无法提供太多帮助。
Hard to say without more information and maybe some code (and I haven't used the WPF Toolkit grid - I use the Infragistics one.) A couple of things:
Are you notifying the UI of property changes (by implementing the INotifyPropertyChanged interface) in your MVVM classes?
You say "after you have updated data on DataTable". Updated how? Through the grid, or through some other means? Are your MVVM classes being "refreshed" correctly (and as such, informing the datagrid/UI that the data has changed)?
I've had varied luck with this stuff. Sometimes the Infragistics grid doesn't update if I add, say, an element to a collection programmatically. I pretty much have to re-read the whole thing for the grid to update. I haven't found the cause yet. Maybe you're dealing with a similar "anomaly" here.
Sorry, not necessarily helpful but maybe enough to point you in the right direction... Can't help much without more information.