How does up work in "View Discovery/Injection" Compostion QuickStarts?

Topics: Prism v2 - WPF 3.5
Oct 20, 2009 at 5:54 PM

Both the "View Discovery Compostion QuickStart" and "View Injection Compostion QuickStart" examples update fields in the EmployeesListView (e.g. First Name) when they are edited in the EmployesDetailView and focus is then set to another field.

Yet, the "BusinessEntities.Employee" class does not implement INotifyPropertyChanged, nor is it a DependencyProperty.

Therefore, my question is, how does the update occur?


Oct 20, 2009 at 8:53 PM

Hi Paul,

The update occurs because the EmployeesListView is binded to an ObservableCollection<T> (which basically prevents you from having to implement INotifyPropertyChanged in your own collection, but it is better explained in the MSDN link I provided). Below is a brief summary of what is going on:

  1. When the employee is selected an event is raised, which passes the Employee as a parameter.
  2. It is handled in the EmployeesPresenter which calls the EmployeeControler.OnEmployeeSelected method.
  3. The controller creates the EmployeeDetailsPresenter and calls its SetSelectedEmployee method, passing the employee as parameter.
  4. The employee properties have a two way binding so the Employee is updated whenever the textboxes are.

As the same Employees are shared, they are automatically modified in the view as it is binding to an ObservableCollection.

Please let me know if this helps.

Damian Schenkelman

Oct 20, 2009 at 10:30 PM

Thanks Damian:

I'm not sure the update I'm referring to has anything to do with ObservableCollection<T>.

Note, I'm referring to editing in the Detail area, which then updates the item in the List area.

I quote from the MSDN documentation:

However, to set up dynamic bindings so that insertions or deletions in the collection update the UI automatically, the collection must implement the INotifyCollectionChanged interface.

And also:

To fully support transferring data values from binding source objects to binding targets, each object in your collection that supports bindable properties must implement an appropriate property changed notification mechanism such as the INotifyPropertyChanged interface.

To verify my uinderstanding, I replaced all the ObservableCollection<T> with List<T> in the "View Injection Compostion QuickStart" sample, and I still observe the update behaviour.

Thus something else must be causing the List item to be updated, yet I fail to see exactly what is doing that.

Thanks for your input, and I await your further comments.