In WPF, is it a best practice to check if the value of a model's property will actually be changed in a property setter, before calling NotifyPropertyChanged?
For example:
private string foobar;
public string Foobar
{
get
{
return this.foobar;
}
set
{
if (value != this.foobar)
{
this.foobar = value;
this.NotifyPropertyChanged("Foobar");
}
}
}
The alternative is to not check and just call NotifyPropertyChanged every time:
private string foobar;
public string Foobar
{
get
{
return this.foobar;
}
set
{
this.foobar = value;
this.NotifyPropertyChanged("Foobar");
}
}
I've seen both styles used in code samples. What, if any, are the advantages and disadvantages of each approach?