-2

I have a master-detail relationship in some custom entities. Say I have the following structure:

    class Master : INotifyPropertyChanged
{
    public int Id { get; set; } // + property changed implementation 
    public string Name { get; set; } // + property changed implementation

    public ObservableCollection<Detail> Details { get; }
    public long sumValue{get{return Details.Sum(x=>x.value -x.discount );}}
}

class Detail : INotifyPropertyChanged
{
     public int Id { get; private set; }
     public string Description { get; set; }
     public double Discont{ get; set; } // + property changed implementation
     public double Value { get; set; } // + property changed implementation
}

if i change row 5 in detail discount Or value How can refresh sumValue? property change dose not worked

i add row 1 and set amount 1 and row sum row is 2000

and add new row 2 set amount 5 and row sum is 10000

but sum in master frezz on last row 2000!

if i call

    NotifyPropertyChange("sumValue");

from master ui updated sumvalue Property!

how can i use

        NotifyPropertyChange("sumValue");

from master Property in Detail Property

like this:

 public double Discont{ get{ return _discount } set{_discount = value; NotifyPropertyChange("sumValue");} }
Arman
  • 47
  • 2
  • 8
  • Does this answer your question? [ObservableCollection and Item PropertyChanged](https://stackoverflow.com/questions/901921/observablecollection-and-item-propertychanged) – Peter Duniho Jun 25 '21 at 16:49

1 Answers1

0

You need to listen on the CollectionChanged of your Details and on any PropertyChanged event of the details in the list. The CollectionChanged event will tell you when objects are added, removed, moved or replaced in the list. But the ObservableCollection does not listen on PropertyChanged events on its content, so you need to do it on your own.

See this answer as a reference how you can do that

Ackdari
  • 3,222
  • 1
  • 16
  • 33
  • Ty I Fix it _commodityModelList.CollectionChanged += _commodityModelList_CollectionChanged; – Arman Jun 25 '21 at 13:19