MVVM将DataGrid(WPF工具包)绑定到DataTable

发布于 2024-08-08 04:21:30 字数 99 浏览 2 评论 0原文

我在我的项目中使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神经大条 2024-08-15 04:21:30

如果没有更多信息和一些代码,很难说(我没有使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文