开发者

How to filter on a constantly updated collection displayed in grid?

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, 开发者_如何学Pythonthe 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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜