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 6945297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:25:05+00:00 2026-05-27T13:25:05+00:00

I found on this link ObservableCollection not noticing when Item in it changes (even

  • 0

I found on this link

ObservableCollection not noticing when Item in it changes (even with INotifyPropertyChanged)

some techniques to notify a Observablecollection that an item has changed. the TrulyObservableCollection in this link seems to be what i’m looking for.

public class TrulyObservableCollection<T> : ObservableCollection<T>
where T : INotifyPropertyChanged
{
    public TrulyObservableCollection()
    : base()
    {
        CollectionChanged += new NotifyCollectionChangedEventHandler(TrulyObservableCollection_CollectionChanged);
    }

    void TrulyObservableCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
    {
        if (e.NewItems != null)
        {
            foreach (Object item in e.NewItems)
            {
                (item as INotifyPropertyChanged).PropertyChanged += new PropertyChangedEventHandler(item_PropertyChanged);
            }
        }
        if (e.OldItems != null)
        {
            foreach (Object item in e.OldItems)
            {
                (item as INotifyPropertyChanged).PropertyChanged -= new PropertyChangedEventHandler(item_PropertyChanged);
            }
        }
    }

    void item_PropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        NotifyCollectionChangedEventArgs a = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset);
        OnCollectionChanged(a);
    }
}

But when I try to use it, I don’t get notifications on the collection. I’m not sure how to correctly implement this in my C# Code:

XAML :

    <DataGrid AutoGenerateColumns="False" ItemsSource="{Binding MyItemsSource, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
        <DataGrid.Columns>
            <DataGridCheckBoxColumn Binding="{Binding MyProperty, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
        </DataGrid.Columns>
    </DataGrid>

ViewModel :

public class MyViewModel : ViewModelBase
{
    private TrulyObservableCollection<MyType> myItemsSource;
    public TrulyObservableCollection<MyType> MyItemsSource
    {
        get { return myItemsSource; }
        set 
        { 
            myItemsSource = value; 
            // Code to trig on item change...
            RaisePropertyChangedEvent("MyItemsSource");
        }
    }

    public MyViewModel()
    {
        MyItemsSource = new TrulyObservableCollection<MyType>()
        { 
            new MyType() { MyProperty = false },
            new MyType() { MyProperty = true },
            new MyType() { MyProperty = false }
        };
    }
}

public class MyType : ViewModelBase
{
    private bool myProperty;
    public bool MyProperty
    {
        get { return myProperty; }
        set 
        {
            myProperty = value;
            RaisePropertyChangedEvent("MyProperty");
        }
    }
}

public class ViewModelBase : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    protected void RaisePropertyChangedEvent(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChangedEventArgs e = new PropertyChangedEventArgs(propertyName);
            PropertyChanged(this, e);
        }
    }
}

When i run the program, i have the 3 checkbox to false, true, false as in the property initialisation.
but when i change the state of one of the ckeckbox, the program go through item_PropertyChanged but never in MyItemsSource Property code.

  • 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-05-27T13:25:06+00:00Added an answer on May 27, 2026 at 1:25 pm

    The spot you have commented as // Code to trig on item change... will only trigger when the collection object gets changed, such as when it gets set to a new object, or set to null.

    With your current implementation of TrulyObservableCollection, to handle the property changed events of your collection, register something to the CollectionChanged event of MyItemsSource

    public MyViewModel()
    {
        MyItemsSource = new TrulyObservableCollection<MyType>();
        MyItemsSource.CollectionChanged += MyItemsSource_CollectionChanged;
    
        MyItemsSource.Add(new MyType() { MyProperty = false });
        MyItemsSource.Add(new MyType() { MyProperty = true});
        MyItemsSource.Add(new MyType() { MyProperty = false });
    }
    
    
    void MyItemsSource_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
    {
        // Handle here
    }
    

    Personally I really don’t like this implementation. You are raising a CollectionChanged event that says the entire collection has been reset, anytime a property changes. Sure it’ll make the UI update anytime an item in the collection changes, but I see that being bad on performance, and it doesn’t seem to have a way to identify what property changed, which is one of the key pieces of information I usually need when doing something on PropertyChanged.

    I prefer using a regular ObservableCollection and just hooking up the PropertyChanged events to it’s items on CollectionChanged. Providing your UI is bound correctly to the items in the ObservableCollection, you shouldn’t need to tell the UI to update when a property on an item in the collection changes.

    public MyViewModel()
    {
        MyItemsSource = new ObservableCollection<MyType>();
        MyItemsSource.CollectionChanged += MyItemsSource_CollectionChanged;
    
        MyItemsSource.Add(new MyType() { MyProperty = false });
        MyItemsSource.Add(new MyType() { MyProperty = true});
        MyItemsSource.Add(new MyType() { MyProperty = false });
    }
    
    void MyItemsSource_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
    {
        if (e.NewItems != null)
            foreach(MyType item in e.NewItems)
                item.PropertyChanged += MyType_PropertyChanged;
    
        if (e.OldItems != null)
            foreach(MyType item in e.OldItems)
                item.PropertyChanged -= MyType_PropertyChanged;
    }
    
    void MyType_PropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        if (e.PropertyName == "MyProperty")
            DoWork();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found this link http://smartclient.codeplex.com/ which has some updates for vs 2010 ....
i found this link.. LINK what i want is there's a JPanel that has
I have found some info on the subject ( like this link) , but
I found this link. Very cool. That shows how you can store appsettings in
I found this link http://artis.imag.fr/~Xavier.Decoret/resources/glsl-mode/ , but there isn't a lot of description around
i have a problem using the Catch Clipboard Events code found on this link
Found this rather strange bug in IE8; element.style.top is limited to 1342177 pixels. Even
I found this open-source library that I want to use in my Java application.
I'm getting this fault intermittently. I found this link which summarises fairly well what
I found this link How to return all records if parameter is null I

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.