我们有一个有孩子集合的父类。这两个类都使用Template10支持更改通知。更改通知在每个类中的作用(即当我们在同一个类中更新一个属性时)如下所示,但是我们无法触发孩子父母的更改通知。RaisePropertyChanged不通知家长
public class ParentViewModel : ViewModelBase
{
public string ParentString { get }
public decimal? Net { get { return Total/(1 + TaxRate/100); } }
public decimal? Tax { get { return Total - Net; } }
decimal? _Total = default(decimal?);
public decimal? Total
{
get
{
return _Total;
}
set
{
Set(ref _Total, value);
RaisePropertyChanged(nameof(Net));
RaisePropertyChanged(nameof(Tax));
}
}
public ObservableCollection<ChildViewModel> MyChildren { get; set; }
我们发现,我们能够使用RaisePropertyChanged
在ParentViewModel
火
Net { get { return Total/(1 + TaxRate/100); } }
和
Tax { get { return Total - Net; } }
在ChildViewModel
我们ChildString
。我们想要通知ParentString
对ChildString
的更改。
public class ChildViewModel : ViewModelBase
{
ParentViewModel MyParent { get; set; }
string _ChildString = default(string);
public string ChildString
{
get
{
return _ChildString;
}
set
{
Set(ref _ChildString, value);
RaisePropertyChanged(nameof(this.MyParent.ParentString));
}
}
但是ParentString
未更新。当ChildString
更新时,我们如何强制更新ParentString
?
其中'this.MyParent'分配?也许[这个问题](http://stackoverflow.com/questions/1427471/observablecollection-not-noticing-when-item-in-it-changes-even-with-inotifypropo)帮助 –
@雷洋MyParent分配通过任何方法创建一个ChildViewModel的实例。谢谢你的链接。被接受的答案对我们来说是诀窍。 – Vague