我有一个类需要调用方法NotifyPropertyChanged
当它的任何属性发生变化时。我在例子中看到的是这样的:getter和setter中的冗余代码
private string property1_;
public string Property1
{
get { return property1_; }
set { property1_ = value; NotifyPropertyChanged(); }
}
private string property2_;
public string Property2
{
get { return property2_; }
set { property2_ = value; NotifyPropertyChanged(); }
}
// .......
这真的是这样做的惯用方法吗?它需要为我想添加的每个属性添加几行样板。而且,如果我想更改属性和字段的名称,我需要更改4个不同的东西。这似乎违反了DRY。
有MVVM框架,可以使这个DRY,就像MVVM Light https://mvvmlight.codeplex.com/! – Fals