Another solution is the one that Robert Rossney suggested in this matter:
WPF INotifyPropertyChanged for read-only related properties
You can create a map of property dependencies (using its code samples):
private static Dictionary<string, string[]> _DependencyMap = new Dictionary<string, string[]> { {"Foo", new[] { "Bar", "Baz" } }, };
and then do it in your OnPropertyChanged:
PropertyChanged(this, new PropertyChangedEventArgs(propertyName)) if (_DependencyMap.ContainsKey(propertyName)) { foreach (string p in _DependencyMap[propertyName]) { PropertyChanged(this, new PropertyChangedEventArgs(p)) } }
You can even bind an attribute to bind the dependent property to the one on which it depends. Something like:
[PropertyChangeDependsOn("Foo")] public int Bar { get { return Foo * Foo; } } [PropertyChangeDependsOn("Foo")] public int Baz { get { return Foo * 2; } }
I have not implemented attribute details yet. Now I better work on it.
schmiddy98
source share