Automatically refresh ICollectionView Filter

后端 未结 2 1883
盖世英雄少女心
盖世英雄少女心 2020-12-13 10:43

Is there any way to automatically update a filter on an ICollectionView without having to call Refresh() when a relevant change has been made?

2条回答
  •  清歌不尽
    2020-12-13 11:01

    For .Net 4.5: There is a new interface which can help to achieve this feature, called : ICollectionViewLiveShaping.

    From MSDN link:

    When live sorting, grouping, or filtering is enabled, a CollectionView will rearrange the position of data in the CollectionView when the data is modified. For example, suppose that an application uses a DataGrid to list stocks in a stock market and the stocks are sorted by stock value. If live sorting is enabled on the stocks' CollectionView, a stock's position in the DataGrid moves when the value of the stock becomes greater or less than another stock's value.

    More Info on above interface: http://www.jonathanantoine.com/2011/10/05/wpf-4-5-%E2%80%93-part-10-live-shaping/


    For .Net 4 and lower: There is also another post on SO QA which might help you: CollectionViewSource Filter not refreshed when Source is changed

提交回复
热议问题