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;
        }
 public static DependencyProperty Register(
     string name,
     Type propertyType,
     Type ownerType,
     PropertyMetadata typeMetadata)
 {
     return Register(name, propertyType, ownerType, typeMetadata, null);
 }
 /// <summary>
 /// Merges the metadata with the base metadata.
 /// </summary>
 /// <param name="baseMetadata">The base metadata to merge.</param>
 /// <param name="property">The property to which the metadata is being applied.</param>
 public virtual void Merge(
     PropertyMetadata baseMetadata, 
     AvaloniaProperty property)
 {
     if (_defaultBindingMode == BindingMode.Default)
     {
         _defaultBindingMode = baseMetadata.DefaultBindingMode;
     }
 }
        private DependencyProperty(
                    bool isAttached,
                    string name,
                    Type propertyType,
                    Type ownerType,
                    PropertyMetadata defaultMetadata,
                    ValidateValueCallback validateValueCallback)
        {
            if (defaultMetadata == null)
            {
                throw new ArgumentNullException("defaultMetadata");
            }

            this.IsAttached = isAttached;
            this.DefaultMetadata = defaultMetadata;
            this.Name = name;
            this.OwnerType = ownerType;
            this.PropertyType = propertyType;
            this.ValidateValueCallback = validateValueCallback;
        }
 public void OverrideMetadata(Type forType, PropertyMetadata typeMetadata)
 {
     this.dependencyProperty.OverrideMetadata(forType, typeMetadata, this);
 }
        public void OverrideMetadata(Type forType, PropertyMetadata typeMetadata, DependencyPropertyKey key)
        {
            if (forType == null)
            {
                throw new ArgumentNullException("forType");
            }

            if (typeMetadata == null)
            {
                throw new ArgumentNullException("typeMetadata");
            }

            // further checking?  should we check
            // key.DependencyProperty == this?
            typeMetadata.Merge(this.DefaultMetadata, this, forType);
            this.metadataByType.Add(forType, typeMetadata);
        }
        public void OverrideMetadata(Type forType, PropertyMetadata typeMetadata)
        {
            if (forType == null)
            {
                throw new ArgumentNullException("forType");
            }

            if (typeMetadata == null)
            {
                throw new ArgumentNullException("typeMetadata");
            }

            if (this.ReadOnly)
            {
                throw new InvalidOperationException(string.Format("Cannot override metadata on readonly property '{0}' without using a DependencyPropertyKey", this.Name));
            }

            typeMetadata.Merge(this.DefaultMetadata, this, forType);
            this.metadataByType.Add(forType, typeMetadata);
        }
 public static DependencyPropertyKey RegisterReadOnly(
     string name,
     Type propertyType,
     Type ownerType,
     PropertyMetadata typeMetadata,
     ValidateValueCallback validateValueCallback)
 {
     DependencyProperty prop = Register(name, propertyType, ownerType, typeMetadata, validateValueCallback);
     prop.ReadOnly = true;
     return new DependencyPropertyKey(prop);
 }
        public DependencyProperty AddOwner(Type ownerType, PropertyMetadata typeMetadata)
        {
            if (typeMetadata == null)
            {
                typeMetadata = new PropertyMetadata();
            }

            this.OverrideMetadata(ownerType, typeMetadata);
            DependencyObject.Register(ownerType, this);

            // MS seems to always return the same DependencyProperty
            return this;
        }
 public static DependencyPropertyKey RegisterAttachedReadOnly(
     string name,
     Type propertyType,
     Type ownerType,
     PropertyMetadata defaultMetadata,
     ValidateValueCallback validateValueCallback)
 {
     throw new NotImplementedException("RegisterAttachedReadOnly(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata, ValidateValueCallback validateValueCallback)");
 }
        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 RegisterAttached(
     string name,
     Type propertyType,
     Type ownerType,
     PropertyMetadata defaultMetadata)
 {
     return RegisterAttached(name, propertyType, ownerType, defaultMetadata, null);
 }
        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;
            }
        }
 internal void Merge(PropertyMetadata baseMetadata, DependencyProperty dp, Type targetType)
 {
     this.Merge(baseMetadata, dp);
     this.OnApply(dp, targetType);
     this.isSealed = true;
 }