private DependencyPropertyDescriptor(PropertyDescriptor property, Type componentType, DependencyProperty dependencyProperty)
     : base(dependencyProperty.Name, null)
 {
     _property = property;
     _componentType = componentType;
     _dependencyProperty = dependencyProperty;
     _metadata = dependencyProperty.GetMetadata(componentType);
 }
Пример #2
0
        private DependencyProperty(bool isAttached, string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata, ValidateValueCallback validateValueCallback)
        {
            if (defaultMetadata == null)
                defaultMetadata = new PropertyMetadata();

            if (defaultMetadata.DefaultValue == null)
            {
                var defaultValue = AutoDefaultValue(propertyType);
                if (validateValueCallback != null && !validateValueCallback(defaultValue))
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Failed to auto generate default value."), "defaultMetadata");
                defaultMetadata.DefaultValue = defaultValue;
            }

            _globalIndex = System.Threading.Interlocked.Increment(ref _lastGlobalIndex);
            IsAttached = isAttached;
            DefaultMetadata = defaultMetadata;
            Name = name;
            OwnerType = ownerType;
            PropertyType = propertyType;
            ValidateValueCallback = validateValueCallback;
        }
Пример #3
0
 internal void DoMerge(PropertyMetadata baseMetadata, DependencyProperty dp, Type targetType)
 {
     Merge(baseMetadata, dp);
     OnApply(dp, targetType);
     _isSealed = true;
 }
Пример #4
0
        protected virtual void Merge(PropertyMetadata baseMetadata, DependencyProperty dp)
        {
            if (baseMetadata == null)
                throw new ArgumentNullException("baseMetadata");

            if (dp == null)
                throw new ArgumentNullException("dp");

            if (_defaultValue == null)
                _defaultValue = baseMetadata._defaultValue;

            if (_propertyChangedCallback == null)
                _propertyChangedCallback = baseMetadata._propertyChangedCallback;

            if (_coerceValueCallback == null)
                _coerceValueCallback = baseMetadata._coerceValueCallback;
        }
Пример #5
0
        public DependencyProperty AddOwner(Type ownerType, PropertyMetadata typeMetadata)
        {
            DependencyObject.Register(ownerType, this);

            if (typeMetadata == null)
                typeMetadata = new PropertyMetadata();

            OverrideMetadata(ownerType, typeMetadata);

            // MS seems to always return the same DependencyProperty
            return this;
        }
Пример #6
0
 public static DependencyPropertyKey RegisterReadOnly(string name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata)
 {
     return RegisterReadOnly(name, propertyType, ownerType, typeMetadata, null);
 }
Пример #7
0
 public static DependencyPropertyKey RegisterReadOnly(string name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata, ValidateValueCallback validateValueCallback)
 {
     ValidateRegisterParameters(name, propertyType, ownerType);
     DependencyProperty dp = Register(name, propertyType, ownerType, typeMetadata, validateValueCallback);
     dp.ReadOnly = true;
     return new DependencyPropertyKey(dp);
 }
Пример #8
0
 public static DependencyProperty RegisterAttached(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata, ValidateValueCallback validateValueCallback)
 {
     ValidateRegisterParameters(name, propertyType, ownerType);
     var dp = new DependencyProperty(true, name, propertyType, ownerType, defaultMetadata, validateValueCallback);
     DependencyObject.Register(ownerType, dp);
     return dp;
 }
Пример #9
0
 public static DependencyPropertyKey RegisterAttachedReadOnly(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata)
 {
     return RegisterAttachedReadOnly(name, propertyType, ownerType, defaultMetadata, null);
 }
Пример #10
0
        public static DependencyProperty Register(string name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata, ValidateValueCallback validateValueCallback)
        {
            ValidateRegisterParameters(name, propertyType, ownerType);
            var dp = new DependencyProperty(false, name, propertyType, ownerType, typeMetadata, validateValueCallback);
            DependencyObject.Register(ownerType, dp);

            // is this needed?
            //dp.OverrideMetadata(ownerType, typeMetadata);

            return dp;
        }
Пример #11
0
        public void OverrideMetadata(Type forType, PropertyMetadata typeMetadata, DependencyPropertyKey key)
        {
            if (forType == null)
                throw new ArgumentNullException("forType");
            if (typeMetadata == null)
                throw new ArgumentNullException("typeMetadata");
            if (key == null)
                throw new ArgumentNullException("key");

            // further checking?  should we check
            // key.DependencyProperty == this?

            typeMetadata.DoMerge(DefaultMetadata, this, forType);
            _metadataByType.TryAdd(forType, typeMetadata);
        }
Пример #12
0
        public void OverrideMetadata(Type forType, PropertyMetadata typeMetadata)
        {
            if (forType == null)
                throw new ArgumentNullException("forType");
            if (typeMetadata == null)
                throw new ArgumentNullException("typeMetadata");

            if (ReadOnly)
                throw new InvalidOperationException(
                    String.Format(CultureInfo.InvariantCulture,
                                  Resources.CannotOverrideMetadataOnReadonlyPropertyWithoutUsingDependencyPropertyKey,
                                  Name));

            typeMetadata.DoMerge(DefaultMetadata, this, forType);
            _metadataByType.TryAdd(forType, typeMetadata);
        }
Пример #13
0
 public void OverrideMetadata(Type forType, PropertyMetadata typeMetadata)
 {
     _dependencyProperty.OverrideMetadata(forType, typeMetadata, this);
 }
Пример #14
0
 public void OverrideMetadata(Type forType, PropertyMetadata typeMetadata)
 {
     _dependencyProperty.OverrideMetadata(forType, typeMetadata, this);
 }