Why ObservableCollection is not updated on items change?

The ObservableCollection has no way of knowing if you make changes to the objects it contains - if you want to be notified when those objects change then you have to make those objects observable as well (for example by having those objects implement INotifyPropertyChanged).

OK then. I implement INotifyPorpertyChanged interface. Thanks – PaN1C_Showt1Me Jul 16 '09 at 11:02.

Another way of achieving this would be that you implement a new XXXViewModel class that derives from DependencyObject and you put this one in the ObservableCollection. For this look at this very good MVVM introduction: blog.lab49.com/archives/2650 an example for such a class would be: public class EntryViewModel : DependencyObject { private Entry _entry; public EntryViewModel(Entry e) { _entry = e; SetProperties(e); } private void SetProperties(Entry value) { this. Id = value.Id; this.

Title = value. Title; this. CreationTimestamp = value.

CreationTimestamp; this. LastUpdateTimestamp = value. LastUpdateTimestamp; this.

Flag = value. Flag; this. Body = value.

Body; } public Entry Entry { get { SyncBackProperties(); return this. _entry; } } public Int64 Id { get { return (Int64)GetValue(IdProperty); } set { SetValue(IdProperty, value); } } // Using a DependencyProperty as the backing store for Id. This enables animation, styling, binding, etc... public static readonly DependencyProperty IdProperty = DependencyProperty.

Register("Id", typeof(Int64), typeof(EntryViewModel), new UIPropertyMetadata(new Int64())); }} important things here: - it derives from DependencyObject - it operates with DependencyProperties to support WPFs databinding br sargola.

– PaN1C_Showt1Me Apr 8 '10 at 9:07 @PaN1C_Showt1Me: GetValue/SetValue are implemented there.Br Sargola – Sargola Apr 8 '10 at 11:17 Ah ok.. The UserControl is a DependencyObject too.. didn't notice that. Thanks – PaN1C_Showt1Me Apr 8 '10 at 14:56.

Probably because items have no way to alert the collection when they are edited - i.e. They might not be observable. Other classes would have similar behavior - no way to alert you to a every change in the graph of referenced classes.

As a work-around, you could extract the object from the collection and then reinsert it after you are done processing. Depending on your requirements and concurrency model, this could just make the program ugly, though. This is a quick hack, and not suitable for anything that requires quality.

Instead, you could implement the collection with an update method that specifically triggers the ContentChanged (not sure about the name) event. It's not pretty, but it is at least quite easy to deal with. Ideally, as kragen2uk says, it would be best to make the objects observable and keep your client code clean and simple.

See also this question.

Extracting and reinserting is a really nice hack :) Now I know that I have to forget about this trick :) – PaN1C_Showt1Me Jul 16 '09 at 11:01.

You can register a method in the view model class aginst the PropertyChanged event of data class objects and listen to them in View model when any change in the property of the data objects happen. This is very easy and straight way to have the control in View model when the items of an observable collection changes. Hope this helps...

Instead, you could implement the collection with an update method that specifically triggers the ContentChanged (not sure about the name) event. It's not pretty, but it is at least quite easy to deal with. Ideally, as kragen2uk says, it would be best to make the objects observable and keep your client code clean and simple.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions