且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PageCollectionView[Bug],使用Filter的时候,删除集合中的元素,会导致ArgumentOutOfRangeException

更新时间:2022-09-16 20:16:58

PageCollectionView,没有使用Filter的时候一切正常;当使用Filter的时候,删除集合中的元素,会抛出如下异常:

   1: 指定的参数已超出有效值的范围。\n参数名: index   
   2: 位于 System.Windows.Data.PagedCollectionView.GetItemAt(Int32 index)\n   
   3: 位于 System.Windows.Data.PagedCollectionView.get_IsCurrentInSync()\n   
   4: 位于 System.Windows.Data.PagedCollectionView.AdjustCurrencyForRemove(Int32 index)\n   
   5: 位于 System.Windows.Data.PagedCollectionView.ProcessRemoveEvent(Object removedItem, Boolean isReplace)\n   
   6: 位于 System.Windows.Data.PagedCollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args)\n   
   7: 位于 System.Windows.Data.PagedCollectionView.<.ctor>b__0(Object sender, NotifyCollectionChangedEventArgs args)\n   
   8: 位于 System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)\n   
   9: 位于 System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)\n   位于 System.Collections.ObjectModel.ObservableCollection`1.RemoveItem(Int32 index)\n   
  10: 位于 System.Collections.ObjectModel.Collection`1.RemoveAt(Int32 index)\n  
  11: 位于 System.Collections.ObjectModel.Collection`1.Remove(T item)\n

 

搜了一圈,找到这篇:ArgumentOutOfRangeException in PageCollectionView

发现是PagedCollectionView的一个bug;更新到最新的SilverLight5,Bug依旧存在。没办法,只好从这里把PagedCollectionView的源代码抓下来,调整并重新编译:

   1: bool needToRemove = (this.PageSize == 0 && removeIndex >= 0) || ( && internalRemoveIndex < (this.PageIndex + 1) * this.PageSize); 

 

记录一下。


本文转自Silent Void博客园博客,原文链接:http://www.cnblogs.com/happyhippy/archive/2012/03/02/2376771.html,如需转载请自行联系原作者