Exemplo n.º 1
0
        private MultiPropertyChangedHandle(Binding[] sources, Action <MultiPropertyChangedCallbackArgs> callback, bool keepAlive)
        {
            if (sources == null)
            {
                throw new ArgumentNullException("sources");
            }
            if (sources.Length == 0)
            {
                throw new ArgumentException("Argument list 'sources' must not be empty.", "sources");
            }
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            this.PropertyChangedHandles = new PropertyChangedHandle[sources.Length];
            this.oldValues         = new object[sources.Length];
            this.callbackProviders = new CallbackProvider[sources.Length];
            for (int i = 0; i < sources.Length; i++)
            {
                this.callbackProviders[i]      = new CallbackProvider(this, i);
                this.PropertyChangedHandles[i] = PropertyChangedHandle.GetDistinctInstance(sources[i], this.callbackProviders[i].OnPropertyChanged);
                this.oldValues[i] = this.PropertyChangedHandles[i].PropertyValue;
            }

            this.Callback  = callback;
            this.KeepAlive = keepAlive;
        }
Exemplo n.º 2
0
            /// <summary>
            /// Initializes a new instance of the <see cref="BindingHandler"/> class.
            /// </summary>
            /// <param name="owner">The PropertyChangedHandle owner instance.</param>
            public BindingHandler(PropertyChangedHandle owner)
            {
                this.owner = owner;
                BindingOperations.SetBinding(this, PropertyProperty, owner.Binding);

                this.initialized = true;
            }
Exemplo n.º 3
0
        // TODO: (PS) Comment this.
        public static bool Equals(object objA, object objB, bool includeCallback)
        {
            PropertyChangedHandle handleA = objA as PropertyChangedHandle;
            PropertyChangedHandle handleB = objB as PropertyChangedHandle;

            return((objA == null && objB == null) || (handleA != null && handleB != null && handleA.Equals(handleB, includeCallback)));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Monitors a property and prints out any changes in the console using Debug.WriteLine(...).
        /// </summary>
        /// <param name="source">The source object that contains the property to monitor.</param>
        /// <param name="path">The path to the property to monitor.</param>
        /// <param name="announceMonitorBegin">if set to <c>true</c> an anouncement is made using Debug.WriteLine(...) when this method is called.</param>
        /// <returns>
        /// The PropertyChangedHandle that is used to monitor the specified property.
        /// </returns>
        public static PropertyChangedHandle MonitorProperty(object source, string path, bool announceMonitorBegin = true)
        {
            if (announceMonitorBegin)
            {
                Debug.WriteLine("Monitoring property path \"{0}\" of source \"{1}\".", path, source);
            }

            return(PropertyChangedHandle.GetDistinctInstance(source, path, PropertyChangeCallback, keepAlive: true));
        }
Exemplo n.º 5
0
        // TODO: (PS) Comment this.
        public bool Equals(object obj, bool includeCallback)
        {
            PropertyChangedHandle other = (PropertyChangedHandle)obj;

            return(other != null &&
                   (object.ReferenceEquals(this, obj) ||
                    (BindingEquals(other.Binding, this.Binding) &&
                     (!includeCallback || object.Equals(other.Callback, this.Callback)) &&
                     this.KeepAlive == other.KeepAlive)));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
        /// <returns>
        ///     <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public override bool Equals(object obj)
        {
            DumbBinding other = obj as DumbBinding;

            return(other != null &&
                   ((this.SourcePropertyChangedHandle != null &&
                     PropertyChangedHandle.Equals(this.SourcePropertyChangedHandle, other.SourcePropertyChangedHandle, false)) ||
                    (this.SourceMultiPropertyChangedHandle != null &&
                     MultiPropertyChangedHandle.Equals(this.SourceMultiPropertyChangedHandle, other.SourceMultiPropertyChangedHandle, false))) &&
                   object.Equals(this.Target, other.Target));
        }
Exemplo n.º 7
0
        // TODO: (PS) Comment this.
        public static PropertyChangedHandle MonitorProperty(Binding binding, bool announceMonitorBegin = true)
        {
            if (binding == null)
            {
                throw new ArgumentNullException("binding");
            }
            if (announceMonitorBegin)
            {
                Debug.WriteLine("Monitoring property path \"{0}\" of source \"{1}\".", binding.Path, binding.Source);
            }

            return(PropertyChangedHandle.GetDistinctInstance(binding, PropertyChangeCallback, keepAlive: true));
        }
Exemplo n.º 8
0
        private static bool DoesBindingRead(BindingBase binding)
        {
            Binding      bindingAsBinding;
            MultiBinding bindingAsMultiBinding;

            if ((bindingAsBinding = binding as Binding) != null)
            {
                return(PropertyChangedHandle.DoesBindingRead(bindingAsBinding));
            }
            else if ((bindingAsMultiBinding = binding as MultiBinding) != null)
            {
                return(bindingAsMultiBinding.Mode == BindingMode.Default || bindingAsMultiBinding.Mode == BindingMode.OneWay || bindingAsMultiBinding.Mode == BindingMode.TwoWay);
            }

            throw new NotSupportedException(String.Format("Binding type {0} not supported.", binding.GetType()));
        }
Exemplo n.º 9
0
        private UniversalEventHandle(Binding binding, UniversalEventCallback callback)
        {
            if (binding == null)
            {
                throw new ArgumentNullException("binding");
            }
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            this.UniversalEventType    = UniversalEventType.PropertyChange;
            this.PropertyChangedHandle = PropertyChangedHandle.GetDistinctInstance(binding, this.OnPropertyChanged);
            this.Callback = callback;

            this.hashCode = HashCodeOperations.Combine(this.PropertyChangedHandle, callback);
        }
Exemplo n.º 10
0
        private DumbBinding(BindingBase bindingToSource, DumbBindingTarget target)
        {
            if (bindingToSource == null)
            {
                throw new ArgumentNullException("bindingToSource");
            }
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            this.BindingToSource           = bindingToSource;
            this.Target                    = target;
            target.PropertyChangedCallback = this.OnTargetPropertyChanged;

            BindingMode? bindingMode = null;
            Binding      bindingToSourceAsBinding;
            MultiBinding bindingToSourceAsMultiBinding;

            if ((bindingToSourceAsBinding = bindingToSource as Binding) != null)
            {
                bindingMode = bindingToSourceAsBinding.Mode;
                this.SourcePropertyChangedHandle = PropertyChangedHandle.GetDistinctInstance(bindingToSourceAsBinding, this.OnSourceValueChanged);
                this.UpdateTarget(this.SourcePropertyChangedHandle.PropertyValue, false);
            }
            else if ((bindingToSourceAsMultiBinding = bindingToSource as MultiBinding) != null)
            {
                bindingMode = bindingToSourceAsMultiBinding.Mode;
                this.SourceMultiPropertyChangedHandle = MultiPropertyChangedHandle.GetDistinctInstance(bindingToSourceAsMultiBinding.Bindings.Cast <Binding>().ToArray(),
                                                                                                       this.OnSourceValuesChanged);
                this.UpdateTarget(this.MultiConvert(this.GetSourceValues()), false);
            }
            else
            {
                throw new NotSupportedException(String.Format("Binding type {0} not supported.", bindingToSource.GetType()));
            }

            if (bindingMode == BindingMode.OneWayToSource)
            {
                this.UpdateSource();
            }
        }
Exemplo n.º 11
0
 // TODO: (PS) Comment this.
 /// <summary>
 /// Initializes a new instance of the <see cref="CollectionObservationHandle"/> class.
 /// </summary>
 /// <param name="source">The source object that contains the property to monitor.</param>
 /// <param name="path">The path from the source object to the property to monitor.</param>
 /// <param name="callback">The callback method that is supposed to be called when changes happen in the property.</param>
 private CollectionObservationHandle(Binding binding, Action <CollectionObservationCallbackArgs> callback, bool keepAlive)
 {
     this.PropertyChangedHandle = PropertyChangedHandle.GetDistinctInstance(binding, this.OnMonitoredPropertyChanged, keepAlive);
     this.UpdateCollectionChangedEventHandler(null, this.PropertyChangedHandle.PropertyValue as INotifyCollectionChanged);
     this.Callback = callback;
 }
Exemplo n.º 12
0
        public bool Equals(object obj, bool includeCallback)
        {
            MultiPropertyChangedHandle other = obj as MultiPropertyChangedHandle;

            return(other != null && (object.ReferenceEquals(this, obj) ||
                                     (this.PropertyChangedHandles.EqualsElementwise(other.PropertyChangedHandles, (x, y) => PropertyChangedHandle.Equals(x, y, false)) &&
                                      (!includeCallback || this.Callback.Equals(other.Callback)))));
        }
Exemplo n.º 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PropertyChangedCallbackArgs"/> class.
 /// </summary>
 /// <param name="handle">The PropertyChangedHandle instance that executes the callback.</param>
 /// <param name="oldValue">The old value of the property that is being watched.</param>
 /// <param name="newValue">The new value of the property that is being watched.</param>
 public PropertyChangedCallbackArgs(PropertyChangedHandle handle, object oldValue, object newValue)
 {
     this.Handle   = handle;
     this.OldValue = oldValue;
     this.NewValue = newValue;
 }