private static void CreateBinding(IOnPropertyChanged sourceObj, string path, string propToNotify) { var pcdo = new PropertyChangeDependencyObject(); var binding = new Binding(path) { Source = sourceObj }; BindingOperations.SetBinding(pcdo, PropertyChangeDependencyObject.PropertyChangeDependencyProperty, binding); pcdo.DependentPropertyChanged += () => sourceObj.OnPropertyChanged(propToNotify); pcdos.Add(pcdo); }
public static void MonitorCollectionChanged(IOnPropertyChanged obj, string prop, Action callback) { var pcdo = new PropertyChangeDependencyObject(); var binding = new Binding(prop) { Source = obj }; BindingOperations.SetBinding(pcdo, PropertyChangeDependencyObject.CollectionChangeDependencyProperty, binding); pcdo.DependentCollectionChanged += () => callback(); pcdos.Add(pcdo); }
public static void Install(IOnPropertyChanged obj) { var type = obj.GetType(); foreach (var prop in type.GetProperties()) { var attribs = prop.GetCustomAttributes(typeof(DependsOnAttribute), true).Cast <DependsOnAttribute>().ToList(); attribs.ForEach(attr => { CreateBinding(obj, attr.BindingPath, prop.Name); }); var attribs2 = prop.GetCustomAttributes(typeof(DependsOnCollectionAttribute), true).Cast <DependsOnCollectionAttribute>().ToList(); attribs2.ForEach(attr => { CreateCollectionBinding(obj, attr.BindingPath, prop.Name); }); } }
public static void RegisterNotifiedObject(IOnPropertyChanged obj, string property) { if (!_otherObjectsToNotify.ContainsKey(property)) _otherObjectsToNotify[property] = new List<IOnPropertyChanged>(); _otherObjectsToNotify[property].Add(obj); }
public static (bool IsEqual, T Value) PropertySet <T>(this IOnPropertyChanged thisValue, ref T backingField, T newValue, [CallerMemberName] string propertyName = "", params string[] additionalPropertyNames) { if (Equals(thisValue, newValue))
public static T PropertyGet <T>(this IOnPropertyChanged thisValue, ref T backingField, [CallerMemberName] string propertyName = "") => backingField;
public static void PropertiesRefresh(this IOnPropertyChanged thisValue) => thisValue.OnPropertyChanged(string.Empty);
public static ICommand Command(this IOnPropertyChanged thisValue, ref ICommand backingField, Action <object> execute) => BindingCommand.Create(ref backingField, execute);