【发布时间】:2015-12-10 00:22:19
【问题描述】:
我有这个 ViewModel:
public class CombustiblesViewModel
{
public List<CombustiblesWCFModel> Combustibles{ get; set; }
public CombustiblesViewModel()
{
Combustibles = _svc.Combustibles_List(sTicket);
}
}
Combustibles_List 从 WCF 服务返回一个列表。 我需要的是跟踪每个 CombustiblesWCFModel 对象的变化。所以我用这段代码扩展了我的模型:
public CombustiblesWCFModel()
{
this.PropertyChanged += ChangedRow;
}
private void ChangedRow(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "HasChanges") return;
CombustiblesWCFModel p = (CombustiblesWCFModel)sender;
// Should Rise HasChanges Property on model, but it doesn't work
p.HasChanges = true;
}
private bool _haschanges;
public bool HasChanges
{
get
{
return _haschanges;
}
set
{
_haschanges = value;
this.RaisePropertyChanged("HasChanges");
}
}
}
我的问题是 HasChanges 总是错误的。我相信从 WCF 服务返回模型时会覆盖 PropertyChanged 事件。
问题
那么如何检测视图模型集合的每个对象上的模型更改?
【问题讨论】:
标签: c# wcf propertychanged