如何跟踪对PageCollectionView sortdescription的更改

时间:2022-04-05 20:10:20

When a DataGrid is bound to a PagedCollectionView the user can resort the data of a given column or collection of columns. This user action manipulates the SortDescriptions collection and when that happens I need to refresh the underlying data with a new query from the server.

当DataGrid绑定到PagedCollectionView时,用户可以使用给定列的数据或列的集合。这个用户操作操作sortdescription集合,当发生这种情况时,我需要使用服务器的新查询刷新底层数据。

Ideally I would attach an event handler to CollectionChanged event of the SortDescriptions property, but I can't since it's is protected.

理想情况下,我将一个事件处理程序附加到sortdescription属性的集合更改事件,但是由于它是受保护的,所以我不能这样做。

What then is the correct method for tracking changes to the SortDescriptions collection of the PagedCollectionView?

那么,如何正确地跟踪PagedCollectionView的sortdescription集合的更改呢?

1 个解决方案

#1


1  

Turns out it's a simple matter of casting the SortDescriptions property to an INotifyCollectionChanged which will expose the CollectionChanged event.

事实证明,将sortdescription属性转换为INotifyCollectionChanged并公开已更改的集合事件是一件简单的事情。

((INotifyCollectionChanged)Data.SortDescriptions).CollectionChanged += (s,e)=> { ... };

#1


1  

Turns out it's a simple matter of casting the SortDescriptions property to an INotifyCollectionChanged which will expose the CollectionChanged event.

事实证明,将sortdescription属性转换为INotifyCollectionChanged并公开已更改的集合事件是一件简单的事情。

((INotifyCollectionChanged)Data.SortDescriptions).CollectionChanged += (s,e)=> { ... };