Skip to content

Instantly share code, notes, and snippets.

@jittuu
Created June 26, 2011 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jittuu/1047463 to your computer and use it in GitHub Desktop.
Save jittuu/1047463 to your computer and use it in GitHub Desktop.
public class Formula<T> : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged = delegate { };
private readonly Func<T> formula;
private readonly INotifyPropertyChanged source;
public Formula(INotifyPropertyChanged source, Func<T> formula, params string[] dependencyProperties)
{
this.source = source;
this.formula = formula;
this.source.PropertyChanged += (sender, arg) =>
{
if (dependencyProperties.Any(p => p == arg.PropertyName))
{
PropertyChanged(this, new PropertyChangedEventArgs("Value"));
}
};
}
public T Value
{
get
{
return formula();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment