Beispiel #1
0
        /// <summary>
        /// Triggers this property to appear changed and causes its its value to be recomputed the next time it's accessed
        /// </summary>
        public void RefreshProperty()
        {
            //ensure we retrieve the value anew the next time it is requested
            this.m_value = new Lazy <TValue>(m_getValueProperty);

            OnValueChanged(s_emptyValueChangedEventArgs);
            m_owner.RaisePropertyChanged(Name);
        }
    public static void RaisePropertyChanged <T>(
        this IRaisePropertyChanged raisePropertyChangedImpl,
        Expression <Func <T> > expr)
    {
        var    memberExprBody = expr.Body as MemberExpression;
        string property       = memberExprBody.Member.Name;

        raisePropertyChangedImpl.RaisePropertyChanged(property);
    }
        public static void SetValueIfDifferent<T>(this IRaisePropertyChanged sourceObject,
                                                  T value,
                                                  ref T field,
                                                  IEqualityComparer<T> equalityComparer,
                                                  [CallerMemberName] string propertyName = null)
        {
            if (equalityComparer.GetHashCode(value) == equalityComparer.GetHashCode(field) &&
                equalityComparer.Equals(value, field))
                return;

            field = value;
            sourceObject.RaisePropertyChanged(propertyName);
        }
Beispiel #4
0
        /// <summary>
        /// Sets a new value for this property; if the new value differs from the old value, a PropertyChanged event will be fired from its owner
        /// </summary>
        /// <param name="newValue">New value to be set</param>
        /// <param name="overrideEqualityCheck">Whether or not to override the equality check.  If true, will raise the change events even if the value is unchanged</param>
        /// <returns>True if the value was changed</returns>
        public virtual bool SetValue(T newValue, bool overrideEqualityCheck)
        {
            if (!overrideEqualityCheck && m_itemChangedComparer.Equals(m_value, newValue))
            {
                return(false);
            }

            m_value = newValue;

            OnValueChanged(s_emptyValueChangedArgs);
            m_owner.RaisePropertyChanged(Name);

            return(true);
        }
        public static void SetValueIfChanged <T>(this IRaisePropertyChanged source,
                                                 ref T field,
                                                 T value,
                                                 IEqualityComparer <T> equalityComparer,
                                                 [CallerMemberName] string propertyName = null)
        {
            if (equalityComparer.GetHashCode(field) == equalityComparer.GetHashCode(value) &&
                equalityComparer.Equals(field, value))
            {
                return;
            }

            field = value;
            source.RaisePropertyChanged(propertyName);
        }
        /// <summary>
        /// Registers a <see cref="INotifyPropertyChanged.PropertyChanged"/> event. If events are not deferred, then the event is raised immediately.
        /// </summary>
        /// <param name="raisePropertyChanged">An object capable of raising <see cref="INotifyPropertyChanged.PropertyChanged"/>. May not be <c>null</c>.</param>
        /// <param name="args">The event arguments to pass to <see cref="INotifyPropertyChanged.PropertyChanged"/>.</param>
        public void Register(IRaisePropertyChanged raisePropertyChanged, PropertyChangedEventArgs args)
        {
            _threadAffinity.VerifyCurrentThread();
            if (raisePropertyChanged == null)
            {
                throw new ArgumentNullException(nameof(raisePropertyChanged));
            }

            if (_referenceCount == 0)
            {
                raisePropertyChanged.RaisePropertyChanged(args);
            }
            else
            {
                _propertiesRequiringNotification.Add(new PropertyChangedNotification(raisePropertyChanged, args));
            }
        }
        private void Caller_PropertyChangedInner(object sender, PropertyChangedEventArgs e, bool bindOnly)
        {
            //Get property
            PropertyInfo property = null;
            object       root     = _caller;

            string[] propPath = e.PropertyName.Split('.');
            for (int i = 0; i < propPath.Length; i++)
            {
                if (property == null)
                {
                    property = _caller.GetType().GetProperty(propPath[i]);
                }
                else
                {
                    root     = property.GetValue(root);
                    property = root.GetType().GetProperty(propPath[i]);
                }
            }
            if (property == null)
            {
                throw new EntryPointNotFoundException(e.PropertyName);
            }

            //Handle attribute bindings
            if (!bindOnly && propDepAttrs.ContainsKey(e.PropertyName))
            {
                IEnumerable <string> dependency = propDepAttrs[e.PropertyName];
                for (int j = 0; j < dependency.Count(); j++)
                {
                    _caller.RaisePropertyChanged(dependency.ElementAt(j));
                }
#if DEBUG
                Debug.WriteLine("PropertyDependencyHandler: Success: " + _caller.GetType().Name + ", Target: " + string.Join(" ", dependency) + ", Invoker: " + e.PropertyName);
#endif
            }
            if (colPropDepAttrs.ContainsKey(e.PropertyName))
            {
                object value = property.GetValue(_caller);
                if (colPropDepAttrs[e.PropertyName].Second != null)
                {
                    ((INotifyCollectionChanged)value).CollectionChanged -= colPropDepAttrs[e.PropertyName].Second.CollectionChanged;
                }
                colPropDepAttrs[e.PropertyName].Second = new CollectionChangedClass(this, e.PropertyName);
                ((INotifyCollectionChanged)value).CollectionChanged += colPropDepAttrs[e.PropertyName].Second.CollectionChanged;
            }
            if (colItemPropDepAttrs.ContainsKey(e.PropertyName))
            {
                object value = property.GetValue(_caller);
                if (colItemPropDepAttrs[e.PropertyName].Second != null)
                {
                    ((IItemPropertyChanged)value).ItemPropertyChanged -= colItemPropDepAttrs[e.PropertyName].Second.ItemPropertyChanged;
                }
                colItemPropDepAttrs[e.PropertyName].Second         = new ItemPropertyChangedClass(this, e.PropertyName);
                ((IItemPropertyChanged)value).ItemPropertyChanged += colItemPropDepAttrs[e.PropertyName].Second.ItemPropertyChanged;
            }
            if (colChildPropDepAttrs.ContainsKey(e.PropertyName))
            {
                object value = property.GetValue(_caller);
                if (colChildPropDepAttrs[e.PropertyName].Second != null)
                {
                    ((INotifyPropertyChanged)value).PropertyChanged -= colChildPropDepAttrs[e.PropertyName].Second.PropertyChanged;
                }
                colChildPropDepAttrs[e.PropertyName].Second      = new ChildPropertyChangedClass(this, e.PropertyName);
                ((INotifyPropertyChanged)value).PropertyChanged += colChildPropDepAttrs[e.PropertyName].Second.PropertyChanged;
            }
        }
Beispiel #8
0
        private void HandlePropertyChanged(string parentPropertyName, PropertyChangedEventArgs args)
        {
            string childPropertyName = string.Join(Separators.Point, parentPropertyName, args.PropertyName);

            RaiseInstance.RaisePropertyChanged(new PropertyChangedEventArgs(childPropertyName));
        }
Beispiel #9
0
 private void RaisePropertyChanged(string propertyName)
 {
     RaiseInstance.RaisePropertyChanged(new PropertyChangedEventArgs(propertyName));
 }