【发布时间】:2021-09-08 20:14:29
【问题描述】:
我在一些自定义实体中有主从关系。假设我有以下结构:
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
}
如果我更改第 5 行的详细折扣或值如何刷新 sumValue?
我添加第 1 行并设置数量 1,行总和为 2000
并添加新的第2行设置数量5,行总和为10000
但在最后一行 2000 的 master frezz 中求和!
如果我打电话
NotifyPropertyChange("sumValue");
从 master ui 更新 sumvalue 属性!
如何使用
NotifyPropertyChange("sumValue");
从主属性到详细属性
像这样:
public double Discont{ get{ return _discount } set{_discount = value; NotifyPropertyChange("sumValue");} }
【问题讨论】:
标签: wpf inotifypropertychanged master-detail