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; }
/// <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; }
// 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))); }
/// <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)); }
// 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))); }
/// <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)); }
// 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)); }
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())); }
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); }
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(); } }
// 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; }
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))))); }
/// <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; }