예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
                });
            }
        }
예제 #4
0
 public static void RegisterNotifiedObject(IOnPropertyChanged obj, string property)
 {
     if (!_otherObjectsToNotify.ContainsKey(property)) _otherObjectsToNotify[property] = new List<IOnPropertyChanged>();
     _otherObjectsToNotify[property].Add(obj);
 }
예제 #5
0
 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))
예제 #6
0
 public static T PropertyGet <T>(this IOnPropertyChanged thisValue, ref T backingField, [CallerMemberName] string propertyName = "")
 => backingField;
예제 #7
0
 public static void PropertiesRefresh(this IOnPropertyChanged thisValue)
 => thisValue.OnPropertyChanged(string.Empty);
예제 #8
0
 public static ICommand Command(this IOnPropertyChanged thisValue, ref ICommand backingField, Action <object> execute)
 => BindingCommand.Create(ref backingField, execute);