Changed Collection of Watched Collections

Real fast-tracked collection. I played with them in Silverlight, doing some of the essential things that I did. It looks like the CollectionChanged event is fired when it is deleted or added to the collection. I would like something to work when I change the property to one of the classes inside the collection. The collection property already has RaisePropertyChanged. Do I need to do something special for the class class itself? Therefore, if I have this:

ObservabelCollection<Person> personcollection... and if I change a property like: Person p = personcollection.where(e => e.FirstName == "Joey").FirstOrDefault(); if (p != null) { p.FirstName = "Joe"; } 

I would expect something to happen in the user interface, but nothing will change.

Any help would be greatly appreciated.

David

+4
source share
4 answers

I see what you are trying to do, but if im correct Observable Collection INotifyCollectionChanged only the INotifyCollectionChanged event when the elements of the collection change. This will cause changes to the user interface.

It doesn’t matter if a property changes on one of its objects in the collection. You will need to implement the INotifyPropertyChanged interface for the properties of these objects in order to cause the user interface to change.

I read here , which gave me some useful information. Although it is designed for WPF, most of them are still in use, since Silverlight is essentially a subset of WPF.

Like this MSDN article, which says:

  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. 
+2
source

To get updates for the Person class, you must implement INotifyPropertyChanged for them.

+2
source

INotifyCollectionChanged should notify someone when the collection has been modified.

INotifyPropertyChanged should notify someone when the property of the object has changed.

The class object must implement the interface and must fire events correctly. Therefore, if you bind it through a Binding object, the user interface can update itself.

ObservableCollection correctly implements INotifyCollectionChanged , but has nothing to do with the objects it contains. Because if the property of the object has changed , which is not a CollectionChanged event . This is a PropertyChanged Event of a specific object in the collection. Therefore, you must implement the INotifyPropertyChanged interface in your Person class.

0
source

ObservableCollection does not report changes to the properties of objects in the collection.

To get this behavior, you will have to bind the INotifyPropertyChanged.PropertyChanged event for each child when they are inserted into your collection. You can do this in the event of the CollectionChanged collection. Remember to cancel events when children are removed from the collection.

0
source

Source: https://habr.com/ru/post/1383981/


All Articles