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

  • Home
  • SEARCH
  • 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 7834969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:25:10+00:00 2026-06-02T13:25:10+00:00

I am confused about how ObservableCollection and INotifyPropertyChanged works. I have this code: Payments

  • 0

I am confused about how ObservableCollection and INotifyPropertyChanged works.

I have this code:

Payments = new ObservableCollection<PaymentViewModel>(_allPayments);

public ObservableCollection<PaymentViewModel> Payments
{
    get { return _payments; }
    set {
        _payments = value;
        RaisePropertyChanged("Payments");
    }
}

I don’t understand what is the relationship between ObservableCollection and INotifyPropertyChanged here. Can you explain?

  • 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. Editorial Team
    Editorial Team
    2026-06-02T13:25:15+00:00Added an answer on June 2, 2026 at 1:25 pm

    ObservableCollection is a specialized collection that can notify subscribers when its contents change, while INotifyPropertyChanged is an interface that allows implementors to notify subscribers when one of their properties changes value.

    You are probably wondering how the two are related (because both are “involved” in the setter in your example).

    Consider this code:

    var model = new MyViewModel(); // assume it's the class with Payments inside
    model.Payments.Add(new PaymentViewModel());
    

    Subscribers to the INotifyCollectionChanged.CollectionChanged event would now know that things have changed and they should update accordingly.

    But now look at this:

    var model = new MyViewModel(); // assume it's the class with Payments inside
    model.Payments.Add(new PaymentViewModel()); // OK, we know what this does
    
    model.Payments = new ObservableCollection<PaymentViewModel>();
    

    After adding an item to the collection we then swap the entire collection for another one. If an ItemsControl is bound to this collection we expect it to update itself and reflect the fact that model.Payments ends up being empty. But how can it do that?

    CollectionChanged will not help because the original collection (after receiving its first item) was not modified; we just discarded it and installed another in its place. The only one who knows that the switch happened is the Payments property setter. So the setter utilizes INotifyPropertyChanged to tell subscribers that the collection has been replaced with another, and they should of course update their status.

    Conclusion: Data binding works automagically in WPF because all the databound controls listen to the INotifyPropertyChanged of their DataContext, and if the binding target implements INotifyCollectionChanged they subscribe to that as well. If the binding target changes they are notified through INotifyPropertyChanged, unsubscribe from INotifyCollectionChanged on the old target and subscribe to it on the new one.

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

Sidebar

Related Questions

Very confused about this one. This code in views.py works, but only when I'm
I am confused about the terms overestimation/underestimation. I perfectly get how A* algorithm works,
Totally confused about the data types required here. I have this Linq statement: var
I'm confused about this bit of code from the HTTP package : type HandlerFunc
I am really confused about object relationships! I have two classes Person and Address.
I'm a bit confused about the right way to write a code. I read
I am a bit confused about this function definition in Prolog: sample(X,[X|Tail]) :- member(X,Tail).
Being confused again after reading about this anti-pattern and the many concerns about it
I've always been confused about this one. Consider the following loops: int [] list
I am a bit confused about how to implement EditorForModel. I get the idea

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.