I have ObservableCollection
that contains class: MyClass
.
private ObservableCollection<MyClass> _myCollection;
public ObservableCollection<MyClass> MyCollection
{
get { return _myCollection; }
set
{
_myCollection= value;
}
}
I want to know in C#
code, if the collection changed.
So I registered to event of the collection: CollectionChanged
it works when I add / delete a record.
Here the registred:
MyCollection.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(MyCollection_CollectionChanged);
I want this event to work (or register another event) when something changes within the class.
At first I thought to register for PropertyChanged
event of the class, then through it run the event CollectionChanged
- it seems complicated and unnecessary.
I think that as the binding
of wpf
can recognize a change in the class and a change in the collection itself, then it is possible to do this through code.
Am I wrong? (More precise question is: Does anyone know a way to this?)