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);
        }
Esempio n. 2
0
        // 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));
        }
Esempio n. 4
0
        // 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;
        }