Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
 public static DependencyProperty Register(
     string name,
     Type propertyType,
     Type ownerType,
     PropertyMetadata typeMetadata)
 {
     return Register(name, propertyType, ownerType, typeMetadata, null);
 }
Exemplo n.º 3
0
 /// <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;
     }
 }
Exemplo n.º 4
0
        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;
        }
Exemplo n.º 5
0
 public void OverrideMetadata(Type forType, PropertyMetadata typeMetadata)
 {
     this.dependencyProperty.OverrideMetadata(forType, typeMetadata, this);
 }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
 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);
 }
Exemplo n.º 9
0
        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;
        }
Exemplo n.º 10
0
 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)");
 }
Exemplo n.º 11
0
        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;
        }
Exemplo n.º 12
0
 public static DependencyProperty RegisterAttached(
     string name,
     Type propertyType,
     Type ownerType,
     PropertyMetadata defaultMetadata)
 {
     return RegisterAttached(name, propertyType, ownerType, defaultMetadata, null);
 }
Exemplo n.º 13
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;
            }
        }
Exemplo n.º 14
0
 internal void Merge(PropertyMetadata baseMetadata, DependencyProperty dp, Type targetType)
 {
     this.Merge(baseMetadata, dp);
     this.OnApply(dp, targetType);
     this.isSealed = true;
 }