Пример #1
0
        public static ViewModelChangePropagation <T> Observe <T>(
            this ViewModelChangePropagation <T> self,
            PropertyChangedEventHandler callback) where T : INotifyPropertyChanged
        {
            if (self.Change.Changed)
            {
                if (self.Change.OldValue != null)
                {
                    self.Change.OldValue.PropertyChanged -= callback;
                }

                if (self.Change.NewValue != null)
                {
                    self.Change.NewValue.PropertyChanged += callback;
                }
            }

            return(self);
        }
Пример #2
0
        public static ViewModelChangePropagation <IReadOnlyCollection <T> > ObserveChildren <T>(
            this ViewModelChangePropagation <IReadOnlyCollection <T> > self,
            PropertyChangedEventHandler callback) where T : INotifyPropertyChanged
        {
            if (self.Change.Changed)
            {
                var removedChildren = self.Change.OldValue.Except(self.Change.NewValue);
                var addedChildren   = self.Change.NewValue.Except(self.Change.OldValue);

                foreach (var child in removedChildren)
                {
                    child.PropertyChanged -= callback;
                }

                foreach (var child in addedChildren)
                {
                    child.PropertyChanged += callback;
                }
            }

            return(self);
        }