Do we need to use both ObservableCollection and INotifyPropertyChanged in order to have all three features (Add/Update/Delete) enabled - WPF ?

Posted on 2011-05-04
Last Modified: 2012-08-13

Can you please let me know:

Do we need to use both ObservableCollection and INotifyPropertyChanged in order to have all three features (Add/Update/Delete) enabled - WPF ?

If yes, can you please provide me a simple example on this ?

Question by:milani_lucie
    LVL 18

    Accepted Solution

    From MS page about Observable collection:
    The objects in your collection must satisfy the requirements described in the Binding Sources Overview. In particular, if you are using OneWay or TwoWay (for example, you want your UI to update when the source properties change dynamically), you must implement a suitable property changed notification mechanism such as the INotifyPropertyChanged interface.

    Here is a sample from one of my classes
    Public Class Payor
        Implements INotifyPropertyChanged

    Open in new window

        Public Event PropertyChanged(ByVal sender As Object, ByVal e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged
        Private _AuthorizationRequired As Boolean

        Protected Overridable Sub OnPropertyChanged(ByVal e As PropertyChangedEventArgs)
            RaiseEvent PropertyChanged(Me, e)
        End Sub

        Public Property AuthorizationRequired() As Boolean
                Return _AuthorizationRequired
            End Get
            Set(ByVal value As Boolean)
                _AuthorizationRequired = value
                OnPropertyChanged(New PropertyChangedEventArgs("AuthorizationRequired"))
            End Set
        End Property

    Author Comment

    Can you please provide sample client code which is binding to a Grid ? I mean consumer code of this collection.

    LVL 40

    Assisted Solution

    For Add/Delete you need INotifyCollectionChanged.CollectionChanged  -

    As far as Update, you need to clarify: Update of what? If you are interested in when an item is replaced, then the CollectionChanged event covers that too, but if you want to know if a property of an item in the collection changed, you need INotifyPropertyChanged to be implemented on the item class itself.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now