I'm using some CLR objects that use the INotifyPropertyChanged interface and use the PropertyChanged function to update in WPF bindings.
Pretty boilerplate:
protected void RaisePropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
Then the property:
private double m_TotalWidgets = 0;
public double TotalWidgets
{
get { return m_TotalWidgets; }
set
{
m_TotalWidgets = value;
RaisePropertyChanged("TotalWidgets");
}
}
Is there a better way to update a derived value or even the whole class?
Say I had a calculated value:
public double ScaledWidgets
{
get
{
return TotalWidgets * CONSTANT_FACTOR;
}
}
I would have to fire ScaledWidget's PropertyChanged when TotalWidgets is updated, eg:
set
{
m_TotalWidgets = value;
RaisePropertyChanged("TotalWidgets");
RaisePropertyChanged("ScaledWidgets");
}
Is there a better way to do this? Is it possible "invalidate" the whole object, especially if there are a lot of derived values? I think it would be kind of lame to fire 100 PropertyChanged events.