Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Question about NotifyCollectionChangedEventArgs

Question about NotifyCollectionChangedEventArgs

Scheduled Pinned Locked Moved WPF
questioncsharpdatabasecomdata-structures
2 Posts 2 Posters 6 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Super Lloyd
    wrote on last edited by
    #1

    The idea with a collection that implements INotifyCollectionChanged, is that it will be (possibly) be used in an ItemsControl, which will get the CollectionViewSource.GetDefaultView(Object) for it, that is likely to be a ListCollectionView. So far... so good... However, as I just discovered today :-O :omg:, when using AddRange(), RemoveRange(), i.e. creating Add/Remove events with more that 1 object will trigger the following error in the ListCollectionView:

    System.NotSupportedException: Range actions are not supported.

    Stack Trace: 
    ListCollectionView.ValidateCollectionChangedEventArgs(NotifyCollectionChangedEventArgs e)
    ListCollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args)
    AbstractInvocation.Proceed()
    Invocation.CallBase() line 147
    ReturnBaseOrDefaultValue.Execute(Invocation invocation) line 88
    IInterceptor.Intercept(Invocation invocation) line 34
    Interceptor.Intercept(IInvocation underlying) line 113
    AbstractInvocation.Proceed()
    NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)

    Mmm... unfortunate... :(( I can think of 2 possible fixes and I am undecided as to which one to use?! 1. When a range Add/Remove event if fired, instead fire a Reset event. 2. When a range Add/Remove event if fired, instead fire multiple Add/Remove single item events. 3. or.. mmm... have a FireEventMode property, which would let the user decide whether to use event as is, split it, or fire Reset. Wo.. what say you?

    A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

    Richard DeemingR 1 Reply Last reply
    0
    • S Super Lloyd

      The idea with a collection that implements INotifyCollectionChanged, is that it will be (possibly) be used in an ItemsControl, which will get the CollectionViewSource.GetDefaultView(Object) for it, that is likely to be a ListCollectionView. So far... so good... However, as I just discovered today :-O :omg:, when using AddRange(), RemoveRange(), i.e. creating Add/Remove events with more that 1 object will trigger the following error in the ListCollectionView:

      System.NotSupportedException: Range actions are not supported.

      Stack Trace: 
      ListCollectionView.ValidateCollectionChangedEventArgs(NotifyCollectionChangedEventArgs e)
      ListCollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args)
      AbstractInvocation.Proceed()
      Invocation.CallBase() line 147
      ReturnBaseOrDefaultValue.Execute(Invocation invocation) line 88
      IInterceptor.Intercept(Invocation invocation) line 34
      Interceptor.Intercept(IInvocation underlying) line 113
      AbstractInvocation.Proceed()
      NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)

      Mmm... unfortunate... :(( I can think of 2 possible fixes and I am undecided as to which one to use?! 1. When a range Add/Remove event if fired, instead fire a Reset event. 2. When a range Add/Remove event if fired, instead fire multiple Add/Remove single item events. 3. or.. mmm... have a FireEventMode property, which would let the user decide whether to use event as is, split it, or fire Reset. Wo.. what say you?

      A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      There's an open issue from 2019 regarding this: Support Bulk Operations in ListCollectionView via ObservableCollection<T> · Issue #1887 · dotnet/wpf · GitHub[^] Personally, I'd be inclined to look at the number of items added / removed, and fire individual events for a "small" number and a reset event for a "large" number. Of course, the definitions of "small" and "large" are up to you. :)


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups