-1

I have a parent viewmodel which has list of person which is the domain object

public class ParentViewModel
{
     public List<Person> Persons{get;set;}

}

I have another viewmodels in different window which uses the person collection.

I am communicating changes by raising Prism Events. The code is bloated with if any changes are in single person or the list, the child viewmodels in different window have to bunch of stuffs.

Is there a way in WPF/.NET to track changes on person which is domain object so that I can raise prism events without going through specific code in which the person (domain object) are changed.

Sharad Shahi
  • 119
  • 1
  • 9

1 Answers1

2

If i understood your need correctly then i would offer 2 options:

  1. Use ObservableCollection instead of a List That will make sure that whoever bind to this list is notified in case of change in the list, a good example you can read in the answer for this question.
  2. But actually i would prefer a cleaner approach which is possible with MVVM-Light so i assume it is possible in Prism as well, and that is - Adding identifier to each person (better is when you can use one of the field as identifier). and then publish a message with the same Identifier so the listeners will subscribe to changes of a person Object with a specific Id.

in other words:
A--> Listener are subscribing to a PersonChangedMessage with a specific person identifier.
B--> Person object change - its publish a message with its identifier.
C--> Only listeners with the correspond id get notified.

A good example you can see here Subscription Filtering

Oran Gerbovski
  • 319
  • 3
  • 7