public void ClearValueTest() { int valueChangedCount = 0; IDependencyPropertyValueEntry dependencyPropertyValue = new DependencyPropertyValueEntry(new DependencyObject(), TestObject.ValueProperty); dependencyPropertyValue.ValueChanged += (sender, e) => valueChangedCount++; int coercedValueChangedCount = 0; IDependencyPropertyValueEntry coercedDependencyPropertyValue = new CoercedDependencyPropertyValueEntry(dependencyPropertyValue, null, CoerceValueCallback); coercedDependencyPropertyValue.ValueChanged += (sender, e) => coercedValueChangedCount++; dependencyPropertyValue.SetBaseValue(0, "base0"); dependencyPropertyValue.SetBaseValue(1, "base1"); dependencyPropertyValue.SetAnimationValue("animation"); Assert.AreEqual("animation-coerced", coercedDependencyPropertyValue.Value); Assert.AreEqual(3, valueChangedCount); Assert.AreEqual(3, coercedValueChangedCount); dependencyPropertyValue.ClearBaseValue(1); Assert.AreEqual("animation-coerced", coercedDependencyPropertyValue.Value); Assert.AreEqual(3, valueChangedCount); Assert.AreEqual(3, coercedValueChangedCount); dependencyPropertyValue.ClearAnimationValue(); Assert.AreEqual("base0-coerced", coercedDependencyPropertyValue.Value); Assert.AreEqual(4, valueChangedCount); Assert.AreEqual(4, coercedValueChangedCount); }
// create dependency property entry and set its default and initial inherited value private IDependencyPropertyValueEntry CreateDependencyPropertyValueEntry(DependencyProperty dependencyProperty) { IDependencyPropertyValueEntry entry = new DependencyPropertyValueEntry(this, dependencyProperty); PropertyMetadata propertyMetadata = dependencyProperty.GetMetadata(GetType()); if (propertyMetadata.CoerceValueCallback != null) { entry = new CoercedDependencyPropertyValueEntry(entry, this, propertyMetadata.CoerceValueCallback); } entry.SetBaseValue((int)BaseValueSource.Default, propertyMetadata.DefaultValue); entry.ValueChanged += (sender, e) => RaisePropertyChanged(new DependencyPropertyChangedEventArgs(dependencyProperty, e.OldValue, e.NewValue)); return(entry); }
public void GetValueTest() { IDependencyPropertyValueEntry dependencyPropertyValue = new DependencyPropertyValueEntry(new DependencyObject(), TestObject.ValueProperty); IDependencyPropertyValueEntry coercedDependencyPropertyValue = new CoercedDependencyPropertyValueEntry(dependencyPropertyValue, null, CoerceValueCallback); dependencyPropertyValue.SetBaseValue(0, "base0"); Assert.AreEqual("base0-coerced", coercedDependencyPropertyValue.Value); Assert.AreEqual("base0", coercedDependencyPropertyValue.GetBaseValue(0, false)); dependencyPropertyValue.SetBaseValue(1, "base1"); Assert.AreEqual("base1-coerced", coercedDependencyPropertyValue.Value); Assert.AreEqual("base1", coercedDependencyPropertyValue.GetBaseValue(1, false)); dependencyPropertyValue.SetAnimationValue("animation"); Assert.AreEqual("animation-coerced", coercedDependencyPropertyValue.Value); Assert.AreEqual("animation", coercedDependencyPropertyValue.GetAnimationValue(false)); }
// create dependency property entry and set its default and initial inherited value private IDependencyPropertyValueEntry CreateDependencyPropertyValueEntry(DependencyProperty dependencyProperty, PropertyMetadata propertyMetadata) { bool isContained = dependencyProperty.IsAttached || dependencyProperty.IsContainedBy(GetType()); IDependencyPropertyValueEntry entry = new DependencyPropertyValueEntry(this, dependencyProperty, isContained ? propertyMetadata.CoerceValueCallback : null); entry.SetBaseValue((int)BaseValueSource.Default, propertyMetadata.DefaultValue); if (isContained) { entry.ValueChanged += containedEntryValueChangedEventHandler; } else { entry.ValueChanged += entryValueChangedEventHandler; } return(entry); }
// create dependency property entry and set its default and initial inherited value private IDependencyPropertyValueEntry CreateDependencyPropertyValueEntry(DependencyProperty dependencyProperty) { IDependencyPropertyValueEntry entry = new DependencyPropertyValueEntry(this, dependencyProperty); PropertyMetadata propertyMetadata = dependencyProperty.GetMetadata(GetType()); if (propertyMetadata.CoerceValueCallback != null) { entry = new CoercedDependencyPropertyValueEntry(entry, this, propertyMetadata.CoerceValueCallback); } entry.SetBaseValue((int)BaseValueSource.Default, propertyMetadata.DefaultValue); entry.ValueChanged += (sender, e) => RaisePropertyChanged(new DependencyPropertyChangedEventArgs(dependencyProperty, e.OldValue, e.NewValue)); return entry; }
public void SetBaseValueTest() { int valueChangedCount = 0; IDependencyPropertyValueEntry dependencyPropertyValue = new DependencyPropertyValueEntry(new DependencyObject(), TestObject.ValueProperty); dependencyPropertyValue.ValueChanged += (sender, e) => valueChangedCount++; ObservableValue observableValue = new ObservableValue("value3"); dependencyPropertyValue.SetBaseValue(0, "value0"); Assert.AreEqual("value0", dependencyPropertyValue.GetBaseValue(false)); Assert.AreEqual(1, valueChangedCount); dependencyPropertyValue.SetBaseValue(0, "value0a"); Assert.AreEqual("value0a", dependencyPropertyValue.GetBaseValue(false)); Assert.AreEqual(2, valueChangedCount); dependencyPropertyValue.SetBaseValue(2, "value2"); Assert.AreEqual("value2", dependencyPropertyValue.GetBaseValue(false)); Assert.AreEqual(3, valueChangedCount); dependencyPropertyValue.SetBaseValue(1, "value1"); Assert.AreEqual("value2", dependencyPropertyValue.GetBaseValue(false)); Assert.AreEqual(3, valueChangedCount); dependencyPropertyValue.SetBaseValue(3, observableValue); Assert.AreEqual(observableValue, dependencyPropertyValue.GetBaseValue(false)); Assert.AreEqual(4, valueChangedCount); observableValue.Value = "value3a"; Assert.AreEqual(observableValue, dependencyPropertyValue.GetBaseValue(false)); Assert.AreEqual(5, valueChangedCount); dependencyPropertyValue.SetBaseValue(4, "value4"); Assert.AreEqual("value4", dependencyPropertyValue.GetBaseValue(false)); Assert.AreEqual(6, valueChangedCount); observableValue.Value = "value3b"; Assert.AreEqual("value4", dependencyPropertyValue.GetBaseValue(false)); Assert.AreEqual(6, valueChangedCount); }
public void SetAnimationValueTest() { int valueChangedCount = 0; IDependencyPropertyValueEntry dependencyPropertyValue = new DependencyPropertyValueEntry(new DependencyObject(), TestObject.ValueProperty); dependencyPropertyValue.ValueChanged += (sender, e) => valueChangedCount++; dependencyPropertyValue.SetBaseValue(0, "base1"); Assert.AreEqual("base1", dependencyPropertyValue.Value); Assert.AreEqual(1, valueChangedCount); dependencyPropertyValue.SetAnimationValue("animation1"); Assert.AreEqual("animation1", dependencyPropertyValue.Value); Assert.AreEqual(2, valueChangedCount); dependencyPropertyValue.SetAnimationValue("animation2"); Assert.AreEqual("animation2", dependencyPropertyValue.Value); Assert.AreEqual(3, valueChangedCount); dependencyPropertyValue.SetBaseValue(0, "base2"); Assert.AreEqual("animation2", dependencyPropertyValue.Value); Assert.AreEqual(3, valueChangedCount); }
public void GetBaseValueTest() { IDependencyPropertyValueEntry dependencyPropertyValue = new DependencyPropertyValueEntry(new DependencyObject(), TestObject.ValueProperty); dependencyPropertyValue.SetAnimationValue("animation1"); dependencyPropertyValue.SetBaseValue(0, "value0"); Assert.AreEqual("value0", dependencyPropertyValue.GetBaseValue(false)); dependencyPropertyValue.SetBaseValue(2, "value2"); Assert.AreEqual("value2", dependencyPropertyValue.GetBaseValue(false)); dependencyPropertyValue.SetBaseValue(1, "value1"); Assert.AreEqual("value2", dependencyPropertyValue.GetBaseValue(false)); Assert.AreEqual("value0", dependencyPropertyValue.GetBaseValue(0, false)); Assert.AreEqual("value1", dependencyPropertyValue.GetBaseValue(1, false)); Assert.AreEqual("value2", dependencyPropertyValue.GetBaseValue(2, false)); }
public void GetAnimationValueTest() { IDependencyPropertyValueEntry dependencyPropertyValue = new DependencyPropertyValueEntry(new DependencyObject(), TestObject.ValueProperty); dependencyPropertyValue.SetAnimationValue("animation1"); Assert.AreEqual("animation1", dependencyPropertyValue.GetAnimationValue(false)); dependencyPropertyValue.SetAnimationValue("animation2"); Assert.AreEqual("animation2", dependencyPropertyValue.GetAnimationValue(false)); dependencyPropertyValue.SetAnimationValue("animation3"); Assert.AreEqual("animation3", dependencyPropertyValue.Value); dependencyPropertyValue.SetAnimationValue("animation4"); Assert.AreEqual("animation4", dependencyPropertyValue.Value); }
public void ClearBaseValueTest() { int valueChangedCount = 0; IDependencyPropertyValueEntry dependencyPropertyValue = new DependencyPropertyValueEntry(new DependencyObject(), TestObject.ValueProperty); dependencyPropertyValue.ValueChanged += (sender, e) => valueChangedCount++; dependencyPropertyValue.SetBaseValue(0, "value0"); dependencyPropertyValue.SetBaseValue(1, "value1"); dependencyPropertyValue.SetBaseValue(2, "value2"); Assert.AreEqual(3, valueChangedCount); dependencyPropertyValue.ClearBaseValue(1); Assert.AreEqual("value2", dependencyPropertyValue.GetBaseValue(false)); Assert.AreEqual(3, valueChangedCount); dependencyPropertyValue.ClearBaseValue(2); Assert.AreEqual("value0", dependencyPropertyValue.GetBaseValue(false)); Assert.AreEqual(4, valueChangedCount); }