【发布时间】:2023-03-14 16:46:01
【问题描述】:
我有一个如下的模型 SupplierInvoice:
public class SupplierInvoice
{
public bool Use { get; set; }
public ApInvoice Invoice { get; set; }
}
还有一个带有此模型列表的 ViewModel:
private List<SupplierInvoice> _SupplierInvoices;
public List<SupplierInvoice> SupplierInvoices
{
get
{
return this._SupplierInvoices;
}
set
{
if (this._SupplierInvoices != value)
{
this._SupplierInvoices = value;
this.RaisePropertyChanged("SupplierInvoices");
}
}
}
在这个 ViewModel 中我也有一个计算属性:
public decimal ApTotal
{
get
{
decimal total = 0;
if (this.SupplierInvoices != null)
{
foreach (SupplierInvoice invoice in this.SupplierInvoices)
{
if (invoice.Use)
{
total += invoice.Invoice.MthInvBal1;
}
}
}
return total;
}
}
此计算属性返回所有发票的余额总和(如果发票的 Use 属性为 true)。使用网格中的复选框在视图上将 Use 属性选择为 true。
现在...问题是:当 SupplierInvoice 模型的 Use 属性已更改时,我如何通知此计算属性 (ApTotal) 的 PropertyChanged?
【问题讨论】:
标签: c# wpf mvvm inotifypropertychanged