【发布时间】:2012-09-27 09:10:06
【问题描述】:
在 WPF 中,是否最好在调用 NotifyPropertyChanged 之前检查模型属性的值是否会在属性设置器中实际更改?
例如:
private string foobar;
public string Foobar
{
get
{
return this.foobar;
}
set
{
if (value != this.foobar)
{
this.foobar = value;
this.NotifyPropertyChanged("Foobar");
}
}
}
另一种方法是不检查,每次都调用 NotifyPropertyChanged:
private string foobar;
public string Foobar
{
get
{
return this.foobar;
}
set
{
this.foobar = value;
this.NotifyPropertyChanged("Foobar");
}
}
我已经在代码示例中看到了这两种样式。每种方法的优缺点是什么?
【问题讨论】:
-
我刚刚看到有人问过同样的问题:stackoverflow.com/questions/2623697/…