public CoercedDependencyPropertyValueEntry(IDependencyPropertyValueEntry source, DependencyObject dependencyObject, CoerceValueCallback coerceValueCallback)
        {
            this.source = source;

            observableValue = new ObservableValue();
            observableValue.ValueChanged += (sender, e) => ValueChanged.Raise(this, e);
            observableValue.Value = source.Value;

            source.ValueChanged += (sender, e) => observableValue.Value = coerceValueCallback(dependencyObject, source.Value);
        }
Example #2
0
        private object GetAnimationBaseValue()
        {
            if (dependencyObject == null)
            {
                return(ObservableValue.UnsetValue);
            }

            IDependencyPropertyValueEntry entry = dependencyObject.GetValueEntry(dependencyProperty);

            return(entry.GetBaseValue(true));
        }
Example #3
0
        public CoercedDependencyPropertyValueEntry(IDependencyPropertyValueEntry source, DependencyObject dependencyObject, CoerceValueCallback coerceValueCallback)
        {
            this.source              = source;
            this.dependencyObject    = dependencyObject;
            this.coerceValueCallback = coerceValueCallback;

            observableValue = new ObservableValue();
            observableValue.ValueChanged += (sender, e) => ValueChanged.Raise(this, e);

            source.ValueChanged += (sender, e) => CoerceValue();
            CoerceValue();
        }
        public void ReadOnlyDependencyPropertiesTest()
        {
            ReadOnlyElement element = new ReadOnlyElement();

            Assert.AreEqual(0, element.Value1);

            element.SetValue(ReadOnlyElement._private_Value1Key, 1);
            Assert.AreEqual(1, element.Value1);

            try
            {
                element.SetValue(ReadOnlyElement.Value1Property, 2);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e is Exception);
            }

            try
            {
                IDependencyPropertyValueEntry entry = element.GetValueEntry(ReadOnlyElement.Value1Property);
                entry.SetBaseValue((int)BaseValueSource.Local, 3);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e is Exception);
            }

            try
            {
                DependencyPropertyKey fakeKey = new DependencyPropertyKey(ReadOnlyElement.Value1Property);
                element.SetValue(fakeKey, 4);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e is Exception);
            }

            try
            {
                DependencyPropertyKey fakeKey = DependencyProperty.RegisterReadOnly("Value1", typeof(int), typeof(ReadOnlyElement), new PropertyMetadata());
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e is Exception);
            }
        }
Example #5
0
        private AnimationExpression GetInitializedAnimationExpression(DependencyProperty dependencyProperty)
        {
            IDependencyPropertyValueEntry entry = GetValueEntry(dependencyProperty);
            AnimationExpression           animationExpression = entry.GetAnimationValue(false) as AnimationExpression;

            if (animationExpression == null)
            {
                animationExpression = new AnimationExpression(this, dependencyProperty);

                entry.SetAnimationValue(animationExpression);
            }

            return(animationExpression);
        }
Example #6
0
        public FrameworkElement()
        {
            Triggers = new ObservableCollection<ITrigger>();
            Triggers.CollectionChanged += OnTriggersCollectionChanged;

            resourcesCache = new CacheDictionary<object, object>(TryResolveResource);

            actualWidthValueEntry = GetValueEntry(ActualWidthPropertyKey);
            actualHeightValueEntry = GetValueEntry(ActualHeightPropertyKey);

            ActualSize = Size.Empty;
            Size = Size.Empty;
            MinSize = Size.Zero;
            MaxSize = Size.Infinity;
        }
Example #7
0
        public FrameworkElement()
        {
            Triggers = new ObservableCollection <ITrigger>();
            Triggers.CollectionChanged += OnTriggersCollectionChanged;

            actualWidthValueEntry  = GetValueEntry(ActualWidthPropertyKey);
            actualHeightValueEntry = GetValueEntry(ActualHeightPropertyKey);

            ActualSize = Size.Empty;
            Size       = Size.Empty;
            MinSize    = Size.Zero;
            MaxSize    = Size.Infinity;

            isDefaultAlignment = true;
        }
Example #8
0
        public FrameworkElement()
        {
            Triggers = new ObservableCollection <ITrigger>();
            Triggers.CollectionChanged += OnTriggersCollectionChanged;

            resourcesCache = new CacheDictionary <object, object>(TryResolveResource);

            actualWidthValueEntry  = GetValueEntry(ActualWidthPropertyKey);
            actualHeightValueEntry = GetValueEntry(ActualHeightPropertyKey);

            ActualSize = Size.Empty;
            Size       = Size.Empty;
            MinSize    = Size.Zero;
            MaxSize    = Size.Infinity;
        }
Example #9
0
        private void SetValue(DependencyProperty dependencyProperty, DependencyPropertyKey dependencyPropertyKey, object value, bool setCurrentValue = false, BaseValueSource source = BaseValueSource.Unknown)
        {
            VerifyReadOnlyProperty(dependencyProperty, dependencyPropertyKey);

            IExpressionProvider newExpressionProvider = value as IExpressionProvider;

            if (newExpressionProvider == null && !dependencyProperty.IsValidValue(value))
            {
                return; // invalid value
            }

            IDependencyPropertyValueEntry entry = GetInitializedValueEntry(dependencyProperty);

            IExpression oldExpression = setCurrentValue ?
                                        entry.GetBaseValue(false) as IExpression : // current value may be set in the top priority expression
                                        entry.GetBaseValue((int)source, false) as IExpression;

            if (newExpressionProvider != null)
            {
                value = newExpressionProvider.CreateExpression(this, dependencyProperty);
            }
            else if (oldExpression != null && oldExpression.SetValue(value))
            {
                return; // value (current or not) was set in the existing expression, nothing else to do
            }

            if (setCurrentValue)
            {
                entry.SetCurrentValue(value);
                return; // base value isn't changed
            }

            if (oldExpression is IDisposable) // expression is being replaced
            {
                ((IDisposable)oldExpression).Dispose();
            }

            entry.SetBaseValue((int)source, value);
            entry.ClearCurrentValue();
        }
Example #10
0
 public RowDefinition()
 {
     actualHeightValueEntry = GetValueEntry(ActualHeightPropertyKey);
 }
 public static object GetBaseValue(this IDependencyPropertyValueEntry entry, int priority, bool flattened)
 {
     return(entry.GetValue(priority, flattened));
 }
 public static void SetBaseValue(this IDependencyPropertyValueEntry entry, int priority, object value)
 {
     entry.SetValue(priority, value);
 }
 public static void ClearBaseValue(this IDependencyPropertyValueEntry entry, int priority)
 {
     entry.SetValue(priority, ObservableValue.UnsetValue);
 }
        public ReadOnlyDependencyPropertyValueEntry(IDependencyPropertyValueEntry source)
        {
            this.source = source;

            source.ValueChanged += (sender, e) => ValueChanged.Raise(this, e);
        }
Example #15
0
 public ColumnDefinition()
 {
     actualWidthValueEntry = GetValueEntry(ActualWidthPropertyKey);
 }
Example #16
0
 public RowDefinition()
 {
     actualHeightValueEntry = GetValueEntry(ActualHeightPropertyKey);
 }
Example #17
0
 public ColumnDefinition()
 {
     actualWidthValueEntry = GetValueEntry(ActualWidthPropertyKey);
 }
Example #18
0
        public ReadOnlyDependencyPropertyValueEntry(IDependencyPropertyValueEntry source)
        {
            this.source = source;

            source.ValueChanged += (sender, e) => ValueChanged.Raise(this, e);
        }
 public static object GetAnimationValue(this IDependencyPropertyValueEntry entry, bool flattened)
 {
     return(entry.GetValue(DependencyPropertyValueEntry.AnimationValuePriority, flattened));
 }
 public static void ClearAnimationValue(this IDependencyPropertyValueEntry entry)
 {
     entry.SetValue(DependencyPropertyValueEntry.AnimationValuePriority, ObservableValue.UnsetValue);
 }
 public static void SetAnimationValue(this IDependencyPropertyValueEntry entry, object value)
 {
     entry.SetValue(DependencyPropertyValueEntry.AnimationValuePriority, value);
 }