I was wondering why there has been made a change in project tracker. The change is made in Rescource.cs and is about adding an eventhandler.
1.
private Resource(){
_assignments =
ResourceAssignments.NewResourceAssignments();_assignments.ListChanged +=
new System.ComponentModel.ListChangedEventHandler(_assignments_ListChanged);}
void _assignments_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e){
OnUnknownPropertyChanged();
}
2.
protected override void OnDeserialized(System.Runtime.Serialization.StreamingContext context){
_assignments.ListChanged +=
new System.ComponentModel.ListChangedEventHandler(_assignments_ListChanged);}
What is exactly the reason for adding these eventhandlers, beside the fact there are now . Yust because I am curious.
This scheme flows the listchanged event up through the root object.
When a child item in the list changes (or an item is added/removed from the list) the ListChanged event is raised.
The parent (Resource) handles that event and raises a PropertyChanged event, telling data binding that it has changed (because a child has changed).
Strictly speaking, there's no reason for doing this in the ProjectTracker app, because changing a child has no cascading effect on any properties of Resource. However, this illustrates the answer to a very common question, which is how to bubble the event from child to list to parent, so now when people ask about it, I can point them to Resource for the answer.
Copyright (c) Marimer LLC