Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 66367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:05:32+00:00 2026-05-10T19:05:32+00:00

Is there a collection (BCL or other) that has the following characteristics: Sends event

  • 0

Is there a collection (BCL or other) that has the following characteristics:

Sends event if collection is changed AND sends event if any of the elements in the collection sends a PropertyChanged event. Sort of an ObservableCollection<T> where T: INotifyPropertyChanged and the collection is also monitoring the elements for changes.

I could wrap an observable collection my self and do the event subscribe/unsubscribe when elements in the collection are added/removed but I was just wondering if any existing collections did this already?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T19:05:32+00:00Added an answer on May 10, 2026 at 7:05 pm

    Made a quick implementation myself:

    public class ObservableCollectionEx<T> : ObservableCollection<T> where T : INotifyPropertyChanged {     protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)     {         Unsubscribe(e.OldItems);         Subscribe(e.NewItems);         base.OnCollectionChanged(e);     }      protected override void ClearItems()     {         foreach(T element in this)             element.PropertyChanged -= ContainedElementChanged;          base.ClearItems();     }      private void Subscribe(IList iList)     {         if (iList != null)         {             foreach (T element in iList)                 element.PropertyChanged += ContainedElementChanged;         }     }      private void Unsubscribe(IList iList)     {         if (iList != null)         {             foreach (T element in iList)                 element.PropertyChanged -= ContainedElementChanged;         }     }      private void ContainedElementChanged(object sender, PropertyChangedEventArgs e)     {         OnPropertyChanged(e);     } } 

    Admitted, it would be kind of confusing and misleading to have the PropertyChanged fire on the collection when the property that actually changed is on a contained element, but it would fit my specific purpose. It could be extended with a new event that is fired instead inside ContainerElementChanged

    Thoughts?

    EDIT: Should note that the BCL ObservableCollection only exposes the INotifyPropertyChanged interface through an explicit implementation so you would need to provide a cast in order to attach to the event like so:

    ObservableCollectionEx<Element> collection = new ObservableCollectionEx<Element>(); ((INotifyPropertyChanged)collection).PropertyChanged += (x,y) => ReactToChange(); 

    EDIT2: Added handling of ClearItems, thanks Josh

    EDIT3: Added a correct unsubscribe for PropertyChanged, thanks Mark

    EDIT4: Wow, this is really learn-as-you-go :). KP noted that the event was fired with the collection as sender and not with the element when the a contained element changes. He suggested declaring a PropertyChanged event on the class marked with new. This would have a few issues which I’ll try to illustrate with the sample below:

      // work on original instance   ObservableCollection<TestObject> col = new ObservableCollectionEx<TestObject>();   ((INotifyPropertyChanged)col).PropertyChanged += (s, e) => { Trace.WriteLine('Changed ' + e.PropertyName); };    var test = new TestObject();   col.Add(test); // no event raised   test.Info = 'NewValue'; //Info property changed raised    // working on explicit instance   ObservableCollectionEx<TestObject> col = new ObservableCollectionEx<TestObject>();   col.PropertyChanged += (s, e) => { Trace.WriteLine('Changed ' + e.PropertyName); };    var test = new TestObject();   col.Add(test); // Count and Item [] property changed raised   test.Info = 'NewValue'; //no event raised 

    You can see from the sample that ‘overriding’ the event has the side effect that you need to be extremely careful of which type of variable you use when subscribing to the event since that dictates which events you receive.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 66k
  • Answers 66k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer CVertex, make sure to review your code, and, if that… May 11, 2026 at 11:26 am
  • added an answer Assign a new NetworkCredential instance to the Credentials property: webClient.Credentials… May 11, 2026 at 11:26 am
  • added an answer .Sort will honor the datatype of the column. Now, if… May 11, 2026 at 11:26 am

Related Questions

Is there a collection (BCL or other) that has the following characteristics: Sends event
Is there a nice way to split a collection into n parts with LINQ?
Is there a way that you can get a collection of all of the
Is there a way to iterate (through foreach preferably) over a collection using reflection?
Is there a way to use a foreach loop to iterate through a collection
Put differently: Is there a good reason to choose a loosely-typed collection over a
Is there a Generics Friendly way of using Collection.EMPTY_LIST in my Java Program. I
Is there any way to read a collection of extension elements with Universal Feed
When designing a collection class, is there any reason not to implement locking privately
Does anyone know if there is a good equivalent to Java's Set collection in

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.