/// <summary>
 /// Notifies multiple property changed
 /// </summary>
 /// <param name="propertyChanged">The property changed event handler that the propertyChangedImplementation holds</param>
 /// <param name="sender">The event sender, optional because it is not required for the Xamarin.Forms view to react to a property changed</param>
 /// <param name="properties"></param>
 /// <remarks>This extension method does not set the event `sender` when notifying property changed. This has not proven to a problem when we created the extension, but be aware of it if you end up with something strange. Set <see cref="sender"/> if you need to make sure that we send the event sender</remarks>
 public static void RaiseForEach(this PropertyChangedEventHandler propertyChanged, object?sender = null, params string[] properties)
 {
     foreach (var property in properties)
     {
         propertyChanged.Raise(property, sender);
     }
 }
 public static void Raise <T>(this PropertyChangedEventHandler handler, object sender, params Expression <Func <T> >[] propertyExpressions)
 {
     foreach (var propertyExpression in propertyExpressions)
     {
         handler.Raise <T>(sender, propertyExpression);
     }
 }
 /// <summary>
 /// Sets a value to a backing field if it passes a equality check and notifies property changed.
 /// </summary>
 /// <typeparam name="S">The type of the property</typeparam>
 /// <param name="backingStore">The backing store that will hold the value of the property</param>
 /// <param name="value">The new value that should be set</param>
 /// <param name="propertyChanged">The property changed event handler that the propertyChangedImplementation holds</param>
 /// <param name="sender">The event sender, optional because it is not required for the Xamarin.Forms view to react to a property changed</param>
 /// <param name="propertyName">A nullable property name, if left empty it will pick the caller member name</param>
 /// <remarks>This method does a equality check to see if the value has changed, if you need to notify property changed when the value has not changed, please use <see cref="Raise"/></remarks>
 /// <remarks>This extension method does not set the event `sender` when notifying property changed. This has not proven to a problem when we created the extension, but be aware of it if you end up with something strange. Set <see cref="sender"/> if you need to make sure that we send the event sender</remarks>
 /// <returns>A boolean value to indicate that the property changed has been invoked</returns>
 public static bool RaiseWhenSet <S>(this PropertyChangedEventHandler propertyChanged, ref S backingStore, S value, object?sender = null, [CallerMemberName] string propertyName = "")
 {
     if (EqualityComparer <S> .Default.Equals(backingStore, value))
     {
         return(false);
     }
     backingStore = value;
     propertyChanged?.Raise(propertyName, sender);
     return(true);
 }
Example #4
0
        public static bool SetPropertyValueAndNotify <T>(this PropertyChangedEventHandler handler, INotifyPropertyChanged sender, ref T storage, T value, [CallerMemberName] String propertyName = null)
        {
            if (object.Equals(storage, value))
            {
                return(false);
            }

            storage = value;

            handler.Raise(sender, propertyName);
            return(true);
        }
Example #5
0
        public static void Raise(this PropertyChangedEventHandler handler, object sender, Expression <Func <object> > propertyExpression)
        {
            if (handler == null || propertyExpression == null)
            {
                return;
            }
            var propertyBodyExpression   = propertyExpression.Body;
            var propertyAccessExpression = propertyBodyExpression.NodeType == ExpressionType.MemberAccess
                ? (MemberExpression)propertyBodyExpression
                : (MemberExpression)((UnaryExpression)propertyBodyExpression).Operand;

            handler.Raise(sender, propertyAccessExpression.Member.Name);
        }
        public static void Raise <T>(this PropertyChangedEventHandler handler, object sender, Expression <Func <T> > propertyExpression)
        {
            var body = propertyExpression.Body as MemberExpression;

            if (body == null)
            {
                throw new ArgumentException("'propertyExpression' should be a member expression");
            }

            var expression = body.Expression as ConstantExpression;

            if (expression == null)
            {
                throw new ArgumentException("'propertyExpression' body should be a constant expression");
            }

            handler.Raise(sender, body.Member.Name);
        }
 public void Raise_WhenPropertySelectorReturnsNull_DoesNothing()
 {
     var handler = new PropertyChangedEventHandler(delegate { });
     handler.Raise(() => null);
 }
 static public void Raise(this PropertyChangedEventHandler handler, object sender, string propertyName)
 {
     handler.Raise(sender, new PropertyChangedEventArgs(propertyName));
 }
 /// <summary>
 /// Notifies property changed.
 /// </summary>
 /// <param name="propertyChangedImplementation">The property changed implementation, this is normally a view model </param>
 /// <param name="propertyChanged">The property changed event handler that the propertyChangedImplementation holds</param>
 /// <param name="propertyName">A nullable property name, if left empty it will pick the caller member name</param>
 public static void OnPropertyChanged(this INotifyPropertyChanged propertyChangedImplementation, PropertyChangedEventHandler?propertyChanged, [CallerMemberName] string propertyName = "")
 {
     propertyChanged?.Raise(propertyName, propertyChangedImplementation);
 }
Example #10
0
 public static void Raise <PropertyType>(this PropertyChangedEventHandler onPropertyChanged, object sender, Expression <Func <PropertyType> > propertyExpression)
 {
     onPropertyChanged.Raise(sender, propertyExpression.GetMemberName());
 }
Example #11
0
 protected virtual void OnPropertyChanged(string propertyName)
 {
     _propertyChanged.Raise(this, propertyName);
 }