如何过滤网格中显示的不断更新的集合?
假设我有一个显示“问题”的 WPF 应用程序。问题可以有不同的状态,例如“未决”和“已回答”。问题存储在 ObservableCollection 中并显示在 DataGrid 上。
我想在顶部有一个切换按钮,可以在“开放”和“已回答”问题之间切换。当用户单击“打开”按钮时,网格应仅显示未解决的问题,当用户单击“已回答”按钮时,网格应仅显示已回答的问题。
这些对象不断地被另一个线程更新(每秒)。此外,它们的状态可以从另一个线程更改,并且网格需要更新。
过滤这个集合的好方法是什么?现在,我正在使用 ICollectionView 并在问题状态更改时调用 Refresh(),但由于在发生“AddItem/EditItem”事务时调用刷新而出现错误。
谢谢。
Let's say I have a WPF application that shows "questions". Questions can have different statuses, such as "open", and "answered". The questions are stored in an ObservableCollection and displayed on a DataGrid.
I want to have a toggle button at the top that switches between "open" and "answered" questions. When a user clicks the "open" button, the grid should display only open questions, and when a user clicks the "answered" button, it should display only answered questions.
These objects are constantly being updated by another thread (every second). In addition, their status can be changed from another thread, and the grid would need to be updated.
What is a good way to filter on this collection? Right now I am using ICollectionView and calling Refresh() when a question's status changes, but I am getting errors due to calling refresh while "AddItem/EditItem" transaction occurring.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您只锁定对 Refresh 的调用以及添加 & 。编辑项目以防止两个线程冲突并导致错误
I would suggest that you just lock the calls to Refresh and the adding & editing of items to prevent the two threads conflicting and causing the errors