Example #1
0
        public void SetBinding(DependencyProperty dp, BindingBase binding)
        {
            Binding b = binding as Binding;

            if (b == null)
            {
                throw new NotSupportedException("Unsupported binding type.");
            }

            this.SetBinding(dp, b);
        }
Example #2
0
        protected virtual void Merge(PropertyMetadata baseMetadata, DependencyProperty dp)
        {
            if (this.defaultValue == null)
            {
                this.defaultValue = baseMetadata.defaultValue;
            }

            if (this.propertyChangedCallback == null)
            {
                this.propertyChangedCallback = baseMetadata.propertyChangedCallback;
            }

            if (this.coerceValueCallback == null)
            {
                this.coerceValueCallback = baseMetadata.coerceValueCallback;
            }
        }
Example #3
0
 public void SetBinding(DependencyProperty dp, string path)
 {
     this.SetBinding(dp, new Binding(path));
 }
Example #4
0
        private object GetDefaultValue(DependencyProperty dp)
        {
            PropertyMetadata metadata = dp.GetMetadata(this);
            FrameworkPropertyMetadata frameworkMetadata = metadata as FrameworkPropertyMetadata;
            object result = metadata.DefaultValue;

            if (frameworkMetadata != null && frameworkMetadata.Inherits)
            {
                if (this.dependencyParent != null)
                {
                    result = this.dependencyParent.GetValue(dp);
                }
            }

            return result;
        }
 internal DependencyPropertyKey(DependencyProperty dependencyProperty)
 {
     this.dependencyProperty = dependencyProperty;
 }
Example #6
0
        internal static void Register(Type t, DependencyProperty dp)
        {
            Dictionary<string, DependencyProperty> typeDeclarations;

            if (!propertyDeclarations.TryGetValue(t, out typeDeclarations))
            {
                typeDeclarations = new Dictionary<string, DependencyProperty>();
                propertyDeclarations.Add(t, typeDeclarations);
            }

            if (!typeDeclarations.ContainsKey(dp.Name))
            {
                typeDeclarations[dp.Name] = dp;
            }
            else
            {
                throw new ArgumentException("A property named " + dp.Name + " already exists on " + t.Name);
            }
        }
Example #7
0
 internal bool IsUnset(DependencyProperty dependencyProperty)
 {
     return !this.properties.ContainsKey(dependencyProperty);
 }
        public static DependencyProperty RegisterAttached(
            string name,
            Type propertyType,
            Type ownerType,
            PropertyMetadata defaultMetadata,
            ValidateValueCallback validateValueCallback)
        {
            if (defaultMetadata == null)
            {
                defaultMetadata = new PropertyMetadata();
            }

            DependencyProperty dp = new DependencyProperty(
                true,
                name,
                propertyType,
                ownerType,
                defaultMetadata,
                validateValueCallback);
            DependencyObject.Register(ownerType, dp);
            return dp;
        }
        public static DependencyProperty Register(
            string name,
            Type propertyType,
            Type ownerType,
            PropertyMetadata typeMetadata,
            ValidateValueCallback validateValueCallback)
        {
            PropertyMetadata defaultMetadata;
            
            if (typeMetadata == null)
            {
                defaultMetadata = typeMetadata = new PropertyMetadata();
            }
            else
            {
                defaultMetadata = new PropertyMetadata(typeMetadata.DefaultValue);
            }

            DependencyProperty dp = new DependencyProperty(
                false,
                name,
                propertyType,
                ownerType,
                defaultMetadata,
                validateValueCallback);

            DependencyObject.Register(ownerType, dp);

            dp.OverrideMetadata(ownerType, typeMetadata);

            return dp;
        }
Example #10
0
 internal LocalValueEntry(DependencyProperty property, object value)
 {
     this.property = property;
     this.value    = value;
 }
Example #11
0
 protected void OnFreezablePropertyChanged(
     DependencyObject oldValue,
     DependencyObject newValue,
     DependencyProperty property)
 {
     throw new NotImplementedException();
 }
Example #12
0
 public Setter(DependencyProperty property, object value, string targetName)
 {
     this.Property = property;
     this.Value = value;
     this.TargetName = targetName;
 }
Example #13
0
 public Setter(DependencyProperty property, object value)
 {
     this.Property = property;
     this.Value = value;
 }
Example #14
0
 protected virtual void OnApply(DependencyProperty dp, Type targetType)
 {
 }
Example #15
0
        public BindingExpression SetBinding(DependencyProperty dp, Binding binding)
        {
            PropertyPathParser pathParser = new PropertyPathParser();
            BindingExpression expression = new BindingExpression(pathParser, this, dp, binding);
            object oldValue = this.GetValue(dp);
            object newValue = expression.GetValue();

            this.propertyBindings.Add(dp, expression);
            this.SetValueInternal(dp, oldValue, newValue);

            return expression;
        }
Example #16
0
        public void ClearValue(DependencyProperty dp)
        {
            if (this.IsSealed)
            {
                throw new InvalidOperationException("Cannot manipulate property values on a sealed DependencyObject");
            }

            this.properties.Remove(dp);
        }
Example #17
0
        public void SetValue(DependencyProperty dp, object value)
        {
            if (this.IsSealed)
            {
                throw new InvalidOperationException("Cannot manipulate property values on a sealed DependencyObject.");
            }

            if (value != DependencyProperty.UnsetValue && !dp.IsValidType(value))
            {
                throw new ArgumentException("Value is not of the correct type for this DependencyProperty.");
            }

            if (dp.ValidateValueCallback != null && !dp.ValidateValueCallback(value))
            {
                throw new Exception("Value does not validate.");
            }

            object oldValue = this.GetValue(dp);
            this.propertyBindings.Remove(dp);
            this.SetValueInternal(dp, oldValue, value);
        }
Example #18
0
 public void CoerceValue(DependencyProperty dp)
 {
     PropertyMetadata pm = dp.GetMetadata(this);
     if (pm.CoerceValueCallback != null)
     {
         pm.CoerceValueCallback(this, this.GetValue(dp));
     }
 }
Example #19
0
 internal bool IsRegistered(Type t, DependencyProperty dp)
 {
     return GetAllProperties(t).Contains(dp);
 }
Example #20
0
        public object GetValue(DependencyProperty dp)
        {
            object val;

            if (!this.properties.TryGetValue(dp, out val))
            {
                val = this.GetDefaultValue(dp);

                if (val == null && dp.PropertyType.IsValueType)
                {
                    val = Activator.CreateInstance(dp.PropertyType);
                }
            }

            return val;
        }
Example #21
0
 protected virtual bool ShouldSerializeProperty(DependencyProperty dp)
 {
     throw new NotImplementedException();
 }
Example #22
0
        public void InvalidateProperty(DependencyProperty dp)
        {
            BindingExpressionBase binding;

            if (this.propertyBindings.TryGetValue(dp, out binding))
            {
                object oldValue = this.GetValue(dp);
                object newValue = binding.GetValue();
                this.SetValueInternal(dp, oldValue, newValue);
            }
        }
Example #23
0
        private void SetValueInternal(DependencyProperty dp, object oldValue, object newValue)
        {
            PropertyMetadata metadata = dp.GetMetadata(this);
            
            if (metadata.CoerceValueCallback != null)
            {
                newValue = metadata.CoerceValueCallback(this, newValue);
            }

            if (newValue != DependencyProperty.UnsetValue && dp.IsValidValue(newValue))
            {
                this.properties[dp] = newValue;
            }
            else
            {
                this.properties.Remove(dp);
                newValue = this.GetValue(dp);
            }

            if (!this.AreEqual(oldValue, newValue))
            {
                this.OnPropertyChanged(new DependencyPropertyChangedEventArgs(dp, oldValue, newValue));
            }
        }
Example #24
0
 public object ReadLocalValue(DependencyProperty dp)
 {
     object val = this.properties[dp];
     return val == null ? DependencyProperty.UnsetValue : val;
 }
Example #25
0
 internal LocalValueEntry(DependencyProperty property, object value)
 {
     this.property = property;
     this.value = value;
 }
Example #26
0
 internal void Merge(PropertyMetadata baseMetadata, DependencyProperty dp, Type targetType)
 {
     this.Merge(baseMetadata, dp);
     this.OnApply(dp, targetType);
     this.isSealed = true;
 }