WPF集合视图源:当前记录是否为最后记录?

时间:2022-06-18 14:04:37

Using CollectionViewSource, is there a "direct" way of knowing if the current record is last one, without doing the comparatively heavy operation of enumerating through all the items to count them (even LINQ would do the same)? I need to enable/disable my navigation buttons depending upon the current position.

使用CollectionViewSource,是否存在一种“直接”方法来知道当前记录是否为最后一个记录,而无需执行枚举所有项以计数它们的相对繁重的操作(即使LINQ也会这样做)?我需要根据当前位置启用/禁用导航按钮。

1 个解决方案

#1


0  

No, there is no direct way of determining whether the its that is current is the last one. A simple Linq Last() on the collection view will find you the last item. Please note, that the Linq Last will not necessarily enumerate the entire collection. If the collection being enumerated supports the IList interface or similar it will be able to locate the last item directly - see the example implementation here.

不,没有直接的方法来确定当前的its是否是最后一个。collection视图上的一个简单的Linq Last()将为您找到最后一项。请注意,Linq最后并不一定要枚举整个集合。如果要枚举的集合支持IList接口或类似的接口,那么它将能够直接定位最后一个条目——请参阅这里的示例实现。

#1


0  

No, there is no direct way of determining whether the its that is current is the last one. A simple Linq Last() on the collection view will find you the last item. Please note, that the Linq Last will not necessarily enumerate the entire collection. If the collection being enumerated supports the IList interface or similar it will be able to locate the last item directly - see the example implementation here.

不,没有直接的方法来确定当前的its是否是最后一个。collection视图上的一个简单的Linq Last()将为您找到最后一项。请注意,Linq最后并不一定要枚举整个集合。如果要枚举的集合支持IList接口或类似的接口,那么它将能够直接定位最后一个条目——请参阅这里的示例实现。