/// <summary> /// Raises the <see cref="PropertyChanging"/> event. /// <para /> /// This is the one and only method that actually raises the <see cref="PropertyChanging"/> event. All other /// methods are (and should be) just overloads that eventually call this method. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.ComponentModel.PropertyChangingEventArgs"/> instance containing the event data.</param> protected virtual void RaisePropertyChanging(object sender, AdvancedPropertyChangingEventArgs e) { var handler = PropertyChanging; if (handler != null) { handler(sender, e); } if (ReferenceEquals(this, sender)) { OnPropertyChanging(e); } }
/// <summary> /// Raises the <see cref="ObservableObject.PropertyChanging"/> event. /// <para/> /// This is the one and only method that actually raises the <see cref="ObservableObject.PropertyChanging"/> event. All other /// methods are (and should be) just overloads that eventually call this method. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.ComponentModel.PropertyChangingEventArgs"/> instance containing the event data.</param> protected override void RaisePropertyChanging(object sender, AdvancedPropertyChangingEventArgs e) { _dispatcherService.BeginInvokeIfRequired(() => base.RaisePropertyChanging(sender, e)); }
protected override void OnPropertyChanging(AdvancedPropertyChangingEventArgs e) { if (string.Equals(e.PropertyName, CancallableProperty.Name)) { e.Cancel = true; } base.OnPropertyChanging(e); }
/// <summary> /// Called when the <see cref="PropertyChanging"/> event occurs. /// </summary> /// <param name="e">The <see cref="System.ComponentModel.PropertyChangingEventArgs"/> instance containing the event data.</param> protected virtual void OnPropertyChanging(AdvancedPropertyChangingEventArgs e) { }
/// <summary> /// Raises the <see cref="ObservableObject.PropertyChanging"/> event. /// <para/> /// This is the one and only method that actually raises the <see cref="ObservableObject.PropertyChanging"/> event. All other /// methods are (and should be) just overloads that eventually call this method. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.ComponentModel.PropertyChangingEventArgs"/> instance containing the event data.</param> protected override void RaisePropertyChanging(object sender, AdvancedPropertyChangingEventArgs e) { _dispatcherService.BeginInvokeIfRequired(() => base.RaisePropertyChanging(sender, e)); }
/// <summary> /// Sets the value of a specific property. /// </summary> /// <param name="property">The property to set.</param> /// <param name="value">Value of the property.</param> /// <param name="notifyOnChange">If <c>true</c>, the <see cref="INotifyPropertyChanged.PropertyChanged"/> event will be invoked.</param> /// <param name="validateAttributes">If set to <c>true</c>, the validation attributes on the property will be validated.</param> /// <exception cref="PropertyNotNullableException">The property is not nullable, but <paramref name="value"/> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="property"/> is <c>null</c>.</exception> internal void SetValue(PropertyData property, object value, bool notifyOnChange, bool validateAttributes) { Argument.IsNotNull("property", property); // Is the object currently read-only (and aren't we changing that)? if (IsReadOnly) { if (property != IsReadOnlyProperty) { Log.Warning("Cannot set property '{0}', object is currently read-only", property.Name); return; } } if (property.IsCalculatedProperty) { Log.Warning("Cannot set property '{0}', the property is a calculated property", property.Name); return; } if (!LeanAndMeanModel) { if ((value != null) && !property.Type.IsInstanceOfTypeEx(value)) { if (!value.GetType().IsCOMObjectEx()) { throw Log.ErrorAndCreateException(msg => new InvalidPropertyValueException(property.Name, property.Type, value.GetType()), "Cannot set value '{0}' to property '{1}' of type '{2}', the value is invalid", value, property.Name, GetType().FullName); } } } var notify = false; object oldValue = null; lock (_propertyValuesLock) { oldValue = GetValueFast <object>(property.Name); var areOldAndNewValuesEqual = ObjectHelper.AreEqualReferences(oldValue, value); if (notifyOnChange && (AlwaysInvokeNotifyChanged || !areOldAndNewValuesEqual) && !LeanAndMeanModel) { var propertyChangingEventArgs = new AdvancedPropertyChangingEventArgs(property.Name); RaisePropertyChanging(this, propertyChangingEventArgs); if (propertyChangingEventArgs.Cancel) { Log.Debug("Change of property '{0}.{1}' is canceled in PropertyChanging event", GetType().FullName, property.Name); return; } } // Validate before assigning, dynamic properties will cause exception if (validateAttributes && !LeanAndMeanModel) { ValidatePropertyUsingAnnotations(property.Name, value, property); } if (!areOldAndNewValuesEqual) { SetValueFast(property.Name, value); } notify = (notifyOnChange && (AlwaysInvokeNotifyChanged || !areOldAndNewValuesEqual) && !LeanAndMeanModel); } // Notify outside lock if (notify) { RaisePropertyChanged(property.Name, oldValue, value); } }
public void DefaultsCancelToFalse() { var e = new AdvancedPropertyChangingEventArgs("test"); Assert.IsFalse(e.Cancel); }
public void SetsPropertyNameCorrectly() { var e = new AdvancedPropertyChangingEventArgs("test"); Assert.AreEqual("test", e.PropertyName); }