0

How can I trigger if the items in the PersonList has changed using ObservesProperty?

public ICommand Save
{
    get
    {
        return _save ?? (_save = 
            new DelegateCommand(saveData,calculate).ObservesProperty(()=> PersonList));
    }
}

public  ObservableCollection<Person> PersonList
{
    get
    {
        return _personList ?? (_personList = new  ObservableCollection<Person>());
    }
    set
    {
        SetProperty(ref _personList , value);
    }
}
svick
  • 236,525
  • 50
  • 385
  • 514
Alex Palacio
  • 3
  • 1
  • 3
  • Why do you want to? I'd try to ask the source of your persons whether one of them is has been changed since last save. Otherwise you can do it the hard way, observe the observable collection and observe all of its elements and maintain a needs-to-be-saved flag for each of them, all manually using handlers for `CollectionChanged` and `PropertyChanged`... – Haukinger Sep 30 '16 at 09:26

1 Answers1

0

You can't. The DelegateCommand.ObservesProperty method only observes ViewModel level properties for change notifications. If you want to respond to each individual item in the list you need to hook into the INPC of those child items. See this SO question for some approaches

ObservableCollection not noticing when Item in it changes (even with INotifyPropertyChanged)

Community
  • 1
  • 1
  • It would have been awesome if I can observe the count property of an observablecollection! I'm using an extra property and I'm subscribing to the CollectionChanged event which is a bummer :( – Amen Jlili Mar 26 '18 at 22:27
  • I believe Prism 7.0 changes this so you can – S1r-Lanzelot Jun 08 '18 at 00:40