예제 #1
0
        /// <summary>
        /// Static ctor for Int16Animation establishes
        /// dependency properties, using as much shared data as possible.
        /// </summary>
        static Int16Animation()
        {
            Type typeofProp = typeof(Int16?);
            Type typeofThis = typeof(Int16Animation);
            PropertyChangedCallback propCallback     = new PropertyChangedCallback(AnimationFunction_Changed);
            ValidateValueCallback   validateCallback = new ValidateValueCallback(ValidateFromToOrByValue);

            FromProperty = DependencyProperty.Register(
                "From",
                typeofProp,
                typeofThis,
                new PropertyMetadata((Int16?)null, propCallback),
                validateCallback);

            ToProperty = DependencyProperty.Register(
                "To",
                typeofProp,
                typeofThis,
                new PropertyMetadata((Int16?)null, propCallback),
                validateCallback);

            ByProperty = DependencyProperty.Register(
                "By",
                typeofProp,
                typeofThis,
                new PropertyMetadata((Int16?)null, propCallback),
                validateCallback);

            EasingFunctionProperty = DependencyProperty.Register(
                "EasingFunction",
                typeof(IEasingFunction),
                typeofThis);
        }
예제 #2
0
        public void SetValue(DependencyProperty dp, object value)
        {
            if (IsSealed)
            {
                throw new InvalidOperationException("Cannot manipulate property values on a sealed DependencyObject");
            }

            //if (!dp.IsValidType (value))
            //	throw new ArgumentException ("value not of the correct type for this DependencyProperty");

            ValidateValueCallback validate = dp.ValidateValueCallback;

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

            object oldValue = null;

            if (properties.ContainsKey(dp))
            {
                oldValue = properties[dp];
            }
            properties[dp] = value;
            if (oldValue != null)
            {
                OnPropertyChanged(new DependencyPropertyChangedEventArgs(dp, oldValue, value));
            }
        }
예제 #3
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;
        }
예제 #4
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;
        }
예제 #5
0
파일: OwnDP.cs 프로젝트: kubast/wpfLight
        static PlaneDP()
        {
            FrameworkPropertyMetadata fpm = new FrameworkPropertyMetadata();

            fpm.PropertyChangedCallback = ChangedCB;
            fpm.BindsTwoWayByDefault    = true;
            fpm.DefaultValue            = 0;


            PropertyChangedCallback pcc = ChangedCB;
            PropertyMetadata        pm  = new PropertyMetadata(0,
                                                               (o, d) => { MessageBox.Show("Changed 1"); },
                                                               (o, d) => { /* MessageBox.Show("Changed 2");*/ return(0); }
                                                               );
            // FrameworkPropertyMetadata fpm = new FrameworkPropertyMetadata(0, FrameworkPropertyMetadataOptions.None, (o, d) => { }, (o,d)=>{ return false; });

            ValidateValueCallback validate = new ValidateValueCallback(value => { return((int)value >= 0); });



            AltitudeProperty = DependencyProperty.Register(
                name: "Altitude",
                propertyType: typeof(int),
                ownerType: typeof(PlaneDP)
                ,
                typeMetadata: fpm,
                validateValueCallback: validate);
            //MaxDistanceProperty = DependencyProperty.Register("Distance", typeof(int), typeof(PlaneDP), fpm, validate);
            //FuelLevelProperty   = DependencyProperty.Register("FuelLevel",typeof(int), typeof(PlaneDP), fpm, validate);
            //  CurrentLoadProperty = DependencyProperty.Register("Load", typeof(int), typeof(PlaneDP), fpm, validate);


            PlaneDP.ExceedEvent = EventManager.RegisterRoutedEvent(
                "Exceed", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(SampleDP));
        }
        /// <summary>
        /// Static ctor for QuaternionAnimation establishes
        /// dependency properties, using as much shared data as possible.
        /// </summary>
        static QuaternionAnimation()
        {
            Type typeofProp = typeof(Quaternion?);
            Type typeofThis = typeof(QuaternionAnimation);
            PropertyChangedCallback propCallback = new PropertyChangedCallback(AnimationFunction_Changed);
            ValidateValueCallback validateCallback = new ValidateValueCallback(ValidateFromToOrByValue);

            FromProperty = DependencyProperty.Register(
                "From",
                typeofProp,
                typeofThis,
                new PropertyMetadata((Quaternion?)null, propCallback),
                validateCallback);

            ToProperty = DependencyProperty.Register(
                "To",
                typeofProp,
                typeofThis,
                new PropertyMetadata((Quaternion?)null, propCallback),
                validateCallback);

            ByProperty = DependencyProperty.Register(
                "By",
                typeofProp,
                typeofThis,
                new PropertyMetadata((Quaternion?)null, propCallback),
                validateCallback);

            EasingFunctionProperty = DependencyProperty.Register(
                "EasingFunction",
                typeof(IEasingFunction),
                typeofThis);
        }
예제 #7
0
        private static DependencyProperty Register(
            string propName, Type ownerType,
            PropertyMetadata typeMetadata = null,
            ValidateValueCallback validateValueCallback = null)
        {
            PropertyInfo property = ownerType.GetProperty(propName);

            if (property == null)
            {
                throw new DependencyHelperException($"'{propName}'속성을 찾을 수 없습니다.");
            }

            if (typeMetadata == null && validateValueCallback == null)
            {
                return(DependencyProperty.Register(propName, property.PropertyType, ownerType));
            }
            else if (typeMetadata != null)
            {
                if (validateValueCallback == null)
                {
                    return(DependencyProperty.Register(propName, property.PropertyType, ownerType, typeMetadata));
                }
                else
                {
                    return(DependencyProperty.Register(propName, property.PropertyType, ownerType, typeMetadata, validateValueCallback));
                }
            }

            throw new ArgumentException();
        }
        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);
        }
예제 #9
0
 public static DependencyProperty RegisterAttached(string name, Type propertyType, Type ownerType,
                                                   PropertyMetadata defaultMetadata,
                                                   ValidateValueCallback validateValueCallback)
 {
     // TODO: What should differ for attached properties???
     return(Register(name, propertyType, ownerType, defaultMetadata, validateValueCallback));
 }
예제 #10
0
        private DependencyProperty(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata, ValidateValueCallback validateValueCallback)
        {
            _name                  = name;
            _propertyType          = propertyType;
            _ownerType             = ownerType;
            _defaultMetadata       = defaultMetadata;
            _validateValueCallback = validateValueCallback;
            Flags flags = default(Flags);

            lock (Synchronized) {
                flags = (Flags)GetUniqueGlobalIndex(ownerType, name);
                RegisteredPropertyList.Add(this);
            }
            if (propertyType.IsValueType)
            {
                flags |= Flags.IsValueType;
            }
            if (propertyType == typeof(object))
            {
                flags |= Flags.IsObjectType;
            }
            if (typeof(Freezable).IsAssignableFrom(propertyType))
            {
                flags |= Flags.IsFreezableType;
            }
            if (propertyType == typeof(string))
            {
                flags |= Flags.IsStringType;
            }
            _packedData = flags;
        }
        void CreateReadOnlyDependencyProperty(
            bool isAttached,
            T identifier,
            string name,
            Type propertyType,
            FrameworkPropertyMetadata metaData,
            ValidateValueCallback validateValueCallback)
        {
            DependencyPropertyKey propertyKey;

            if (isAttached)
            {
                propertyKey = DependencyProperty.RegisterAttachedReadOnly(
                    name,
                    propertyType,
                    OwnerType,
                    metaData,
                    validateValueCallback);
            }
            else
            {
                propertyKey = DependencyProperty.RegisterReadOnly(
                    name,
                    propertyType,
                    OwnerType,
                    metaData,
                    validateValueCallback);
            }
            _readOnlyProperties.Add(identifier, propertyKey);

            DependencyProperty property = propertyKey.DependencyProperty;

            Properties.Add(identifier, property);
        }
예제 #12
0
 /// <summary> Initializes a new instance of the BusinessValueMetadata class with the specified settings and callbacks.
 /// </summary>
 /// <param name="settings"></param>
 /// <param name="validateValueCallback">A reference to a callback that should perform any custom validation of the business value value beyond typical type validation.</param>
 /// <param name="valueChangedCallback">A reference to a handler implementation that the property system will call whenever the effective value of the property changes.</param>
 /// <param name="coerceValueCallback">A reference to a handler implementation will be called whenever the property system calls CoerceValue for the business value.</param>
 public BusinessValueMetadata(IValueSettings settings, ValidateValueCallback validateValueCallback, BusinessValueChangedCallback valueChangedCallback, CoerceValueCallback coerceValueCallback)
 {
     _settings = settings;
     _validateValueCallback = validateValueCallback;
     _valueChangedCallback  = valueChangedCallback;
     _coerceValueCallback   = coerceValueCallback;
 }
예제 #13
0
        static CornerRadiusAnimation()
        {
            Type typeofProp = typeof(CornerRadius?);
            Type typeofThis = typeof(CornerRadiusAnimation);
            PropertyChangedCallback propCallback     = new PropertyChangedCallback(AnimationFunction_Changed);
            ValidateValueCallback   validateCallback = new ValidateValueCallback(ValidateFromToOrByValue);

            FromProperty = DependencyProperty.Register(
                "From",
                typeofProp,
                typeofThis,
                new PropertyMetadata((CornerRadius?)null, propCallback),
                validateCallback);

            ToProperty = DependencyProperty.Register(
                "To",
                typeofProp,
                typeofThis,
                new PropertyMetadata((CornerRadius?)null, propCallback),
                validateCallback);

            ByProperty = DependencyProperty.Register(
                "By",
                typeofProp,
                typeofThis,
                new PropertyMetadata((CornerRadius?)null, propCallback),
                validateCallback);
        }
예제 #14
0
        static CornerRadiusAnimation()
        {
            Type typeofProp = typeof(CornerRadius?);
            Type typeofThis = typeof(CornerRadiusAnimation);
            PropertyChangedCallback propCallback = new PropertyChangedCallback(AnimationFunction_Changed);
            ValidateValueCallback validateCallback = new ValidateValueCallback(ValidateFromToOrByValue);

            FromProperty = DependencyProperty.Register(
                "From",
                typeofProp,
                typeofThis,
                new PropertyMetadata((CornerRadius?)null, propCallback),
                validateCallback);

            ToProperty = DependencyProperty.Register(
                "To",
                typeofProp,
                typeofThis,
                new PropertyMetadata((CornerRadius?)null, propCallback),
                validateCallback);

            ByProperty = DependencyProperty.Register(
                "By",
                typeofProp,
                typeofThis,
                new PropertyMetadata((CornerRadius?)null, propCallback),
                validateCallback);
        }
 internal FunctionalProperty(string name, Type propertyType, Type ownerType, FunctionalPropertyMetadata typeMetadata, ValidateValueCallback validateValueCallback)
 {
     Name = name;
     PropertyType = propertyType;
     OwnerType = ownerType;
     DefaultMetadata = typeMetadata;
     ValidateValueCallback = validateValueCallback;
 }
예제 #16
0
 private static RadPropertyMetadata AutoGeneratePropertyMetadata(
     Type propertyType,
     ValidateValueCallback validateValueCallback,
     string name,
     Type ownerType)
 {
     return(new RadPropertyMetadata(RadProperty.AutoGenerateDefaultValue(propertyType)));
 }
예제 #17
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)");
 }
 /// <summary> Initializes a new instance of the <see cref="ViewModelProperty"/> class.
 /// </summary>
 /// <param name="name">The name of the property</param>
 /// <param name="propertyType">Type of the property.</param>
 /// <param name="ownerType">Type of the owner.</param>
 /// <param name="typeMetadata">The type metadata.</param>
 /// <param name="validateValueCallback">The validate value callback.</param>
 /// <param name="readOnly">if set to <c>true</c> [read only].</param>
 /// <remarks></remarks>
 protected ViewModelProperty(string name, Type propertyType, Type ownerType, ViewModelMetadata typeMetadata, ValidateValueCallback validateValueCallback, bool readOnly)
 {
     _Name                  = name;
     _PropertyType          = propertyType;
     _OwnerType             = ownerType;
     _DefaultMetadata       = typeMetadata;
     _ValidateValueCallback = validateValueCallback;
     _ReadOnly              = readOnly;
 }
예제 #19
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));
        }
        // Methods
        static LinearGradientBrushAnimation()
        {
            Type propertyType = typeof(LinearGradientBrush);
            Type ownerType    = typeof(LinearGradientBrushAnimation);
            PropertyChangedCallback propertyChangedCallback = new PropertyChangedCallback(LinearGradientBrushAnimation.AnimationFunction_Changed);
            ValidateValueCallback   validateValueCallback   = new ValidateValueCallback(LinearGradientBrushAnimation.ValidateValues);

            FromProperty = DependencyProperty.Register("From", propertyType, ownerType, new PropertyMetadata(null, propertyChangedCallback), validateValueCallback);
            ToProperty   = DependencyProperty.Register("To", propertyType, ownerType, new PropertyMetadata(null, propertyChangedCallback), validateValueCallback);
        }
예제 #21
0
        public static DependencyProperty <AnyType> Register(string name, Type propertyType,
                                                            Type ownerType, PropertyMetadata typeMetadata,
                                                            ValidateValueCallback validateValueCallback)
        {
            DependencyProperty <AnyType> retVal = new DependencyProperty <AnyType>(name, propertyType, ownerType,
                                                                                   typeMetadata, validateValueCallback);

            dependencyPropertyList.Add(retVal);
            return(retVal);
        }
예제 #22
0
        public static DependencyProperty RegisterAttached(string name, Type propertyType, Type ownerType,
                                                          PropertyMetadata defaultMetadata,
                                                          ValidateValueCallback validateValueCallback)
        {
            DependencyProperty dp = new DependencyProperty(true, name, propertyType, ownerType,
                                                           defaultMetadata, validateValueCallback);

            DependencyObject.register(ownerType, dp);
            return(dp);
        }
예제 #23
0
 public static RadProperty RegisterAttached(
     string name,
     Type propertyType,
     Type ownerType,
     RadPropertyMetadata typeMetadata,
     ValidateValueCallback validateValueCallback)
 {
     RadProperty.RegisterParameterValidation(name, propertyType, ownerType);
     return(RadProperty.RegisterCommon(name, propertyType, ownerType, AttachedPropertyUsage.Anywhere, typeMetadata, validateValueCallback));
 }
예제 #24
0
 private DependencyProperty(string aName, Type aPropertyType,
                            Type anOwnerType, PropertyMetadata aTypeMetadata,
                            ValidateValueCallback aValidateValueCallback)
 {
     name                  = aName;
     propertyType          = aPropertyType;
     ownerType             = anOwnerType;
     typeMetadata          = aTypeMetadata;
     validateValueCallback = aValidateValueCallback;
 }
예제 #25
0
 private DependencyProperty(bool isAttached, string name, Type propertyType, Type ownerType,
                            PropertyMetadata defaultMetadata,
                            ValidateValueCallback validateValueCallback)
 {
     IsAttached            = isAttached;
     DefaultMetadata       = (defaultMetadata == null ? new PropertyMetadata() : defaultMetadata);
     Name                  = name;
     OwnerType             = ownerType;
     PropertyType          = propertyType;
     ValidateValueCallback = validateValueCallback;
 }
예제 #26
0
		private DependencyProperty (bool isAttached, string name, Type propertyType, Type ownerType,
					    PropertyMetadata defaultMetadata,
					    ValidateValueCallback validateValueCallback)
		{
			IsAttached = isAttached;
			DefaultMetadata = (defaultMetadata == null ? new PropertyMetadata() : defaultMetadata);
			Name = name;
			OwnerType = ownerType;
			PropertyType = propertyType;
			ValidateValueCallback = validateValueCallback;
		}
    private DependencyProperty(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata,
                               ValidateValueCallback validateValueCallback)
    {
      _name = name;
      _propertyType = propertyType;
      _ownerType = ownerType;
      _defaultMetadata = defaultMetadata;
      _validateValueCallback = validateValueCallback;

      _properties[name + ownerType] = this;
    }
        ///<exception cref="ArgumentException"></exception>
        public static DependencyPropertyKey RegisterReadOnly <TOwner, TProperty>(
            Expression <Func <TOwner, TProperty> > propertyExpression,
            PropertyMetadata propertyMetadata           = null,
            ValidateValueCallback validateValueCallback = null)
        {
            var name        = PropertyNameExtractor.Extract(propertyExpression);
            var propertyKey = DependencyProperty.RegisterReadOnly(
                name, typeof(TProperty), typeof(TOwner), propertyMetadata, validateValueCallback);

            return(propertyKey);
        }
예제 #29
0
 public static DependencyPropertyKey RegisterReadOnly <TOwner>(
     Expression <Func <TOwner, object> > property,
     PropertyMetadata metadata,
     ValidateValueCallback validateValueCallback)
 {
     return(DependencyProperty.RegisterReadOnly(typeof(TOwner).GetPropertyName(property),
                                                typeof(TOwner).GetPropertyType(property),
                                                typeof(TOwner),
                                                metadata,
                                                validateValueCallback));
 }
예제 #30
0
        private DependencyProperty(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata,
                                   ValidateValueCallback validateValueCallback)
        {
            _name                  = name;
            _propertyType          = propertyType;
            _ownerType             = ownerType;
            _defaultMetadata       = defaultMetadata;
            _validateValueCallback = validateValueCallback;

            _properties[name + ownerType] = this;
        }
예제 #31
0
        // Token: 0x0600173A RID: 5946 RVA: 0x00071F14 File Offset: 0x00070114
        static ThicknessAnimation()
        {
            Type typeFromHandle  = typeof(Thickness?);
            Type typeFromHandle2 = typeof(ThicknessAnimation);
            PropertyChangedCallback propertyChangedCallback = new PropertyChangedCallback(ThicknessAnimation.AnimationFunction_Changed);
            ValidateValueCallback   validateValueCallback   = new ValidateValueCallback(ThicknessAnimation.ValidateFromToOrByValue);

            ThicknessAnimation.FromProperty           = DependencyProperty.Register("From", typeFromHandle, typeFromHandle2, new PropertyMetadata(null, propertyChangedCallback), validateValueCallback);
            ThicknessAnimation.ToProperty             = DependencyProperty.Register("To", typeFromHandle, typeFromHandle2, new PropertyMetadata(null, propertyChangedCallback), validateValueCallback);
            ThicknessAnimation.ByProperty             = DependencyProperty.Register("By", typeFromHandle, typeFromHandle2, new PropertyMetadata(null, propertyChangedCallback), validateValueCallback);
            ThicknessAnimation.EasingFunctionProperty = DependencyProperty.Register("EasingFunction", typeof(IEasingFunction), typeFromHandle2);
        }
        public void Should_Set_ValidateValueCallback()
        {
            ValidateValueCallback validateValueCallback = v => { return(true); };

            DependencyProperty dp = DependencyProperty.Register(
                "Register_Should_Set_ValidateValueCallback",
                typeof(string),
                typeof(TestClass1),
                null,
                validateValueCallback);

            Assert.AreEqual(validateValueCallback, dp.ValidateValueCallback);
        }
예제 #33
0
        static CornerAnimation()
        {
            var propertyType = typeof(CornerRadius?);
            var ownerType    = typeof(CornerAnimation);
            PropertyChangedCallback propertyChangedCallback = AnimationFunction_Changed;
            ValidateValueCallback   validateValueCallback   = ValidateFromToOrByValue;

            FromProperty = DependencyProperty.Register("From", propertyType, ownerType,
                                                       new PropertyMetadata(null, propertyChangedCallback), validateValueCallback);
            ToProperty             = DependencyProperty.Register("To", propertyType, ownerType, new PropertyMetadata(null, propertyChangedCallback), validateValueCallback);
            ByProperty             = DependencyProperty.Register("By", propertyType, ownerType, new PropertyMetadata(null, propertyChangedCallback), validateValueCallback);
            EasingFunctionProperty = DependencyProperty.Register("EasingFunction", typeof(IEasingFunction), ownerType);
        }
        public void Should_Throw_ArgumentException_If_DefaultValid_Is_Invalid()
        {
            ValidateValueCallback validateValueCallback = v =>
            {
                return(false);
            };

            DependencyProperty dp = DependencyProperty.Register(
                "Register_Should_Throw_ArgumentException_If_DefaultValid_Is_Invalid",
                typeof(string),
                typeof(TestClass1),
                new PropertyMetadata("foobar"),
                validateValueCallback);
        }
예제 #35
0
 private DependencyProperty(ValidateValueCallback validateValueCallback, PropertyMetadata defaultMetadata, Type ownerType, Type propertyType, string name, bool readOnly = false)
 {
     if (!ownerType.IsSubclassOf(typeof(DependencyObject)))
     {
         throw new ArgumentException($"ownerType 必须是继承于DependencyObject,ownerType类型{ownerType.FullName}");
     }
     ValidateValueCallback = validateValueCallback;
     DefaultMetadata       = defaultMetadata ?? throw new ArgumentException("defaultMetadata 不能为Null");
     OwnerType             = ownerType;
     PropertyType          = propertyType;
     Name        = name;
     GlobalIndex = ++id;
     ReadOnly    = readOnly;
 }
예제 #36
0
        /// <summary>
        ///  Simple registration, metadata, validation, and a read-only property
        /// key.  Calling this version restricts the property such that it can
        /// only be set via the corresponding overload of DependencyObject.SetValue.
        /// </summary>
        public static DependencyPropertyKey RegisterReadOnly(
            string name,
            Type propertyType,
            Type ownerType,
            PropertyMetadata typeMetadata,
            ValidateValueCallback validateValueCallback)
        {
            RegisterParameterValidation(name, propertyType, ownerType);

            PropertyMetadata defaultMetadata = null;

            if (typeMetadata != null && typeMetadata.DefaultValueWasSet())
            {
                defaultMetadata = new PropertyMetadata(typeMetadata.DefaultValue);
            }
            else
            {
                defaultMetadata = AutoGeneratePropertyMetadata(propertyType, validateValueCallback, name, ownerType);
            }

            //  We create a DependencyPropertyKey at this point with a null property
            // and set that in the _readOnlyKey field.  This is so the property is
            // marked as requiring a key immediately.  If something fails in the
            // initialization path, the property is still marked as needing a key.
            //  This is better than the alternative of creating and setting the key
            // later, because if that code fails the read-only property would not
            // be marked read-only.  The intent of this mildly convoluted code
            // is so we fail securely.
            DependencyPropertyKey authorizationKey = new DependencyPropertyKey(null); // No property yet, use null as placeholder.

            DependencyProperty property = RegisterCommon(name, propertyType, ownerType, defaultMetadata, validateValueCallback);

            property._readOnlyKey = authorizationKey;

            authorizationKey.SetDependencyProperty(property);

            if (typeMetadata == null)
            {
                // No metadata specified, generate one so we can specify the authorized key.
                typeMetadata = AutoGeneratePropertyMetadata(propertyType, validateValueCallback, name, ownerType);
            }

            // Authorize registering type for read-only access, create key.
            #pragma warning suppress 6506 // typeMetadata is never null, since we generate default metadata if none is provided.

            // Apply type-specific metadata to owner type only
            property.OverrideMetadata(ownerType, typeMetadata, authorizationKey);

            return(authorizationKey);
        }
예제 #37
0
 public static DependencyProperty Register(string name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata, ValidateValueCallback validateValueCallback)
 {
     PropertyMetadata defaultMetadata = null;
     if (typeMetadata != null && typeMetadata.DefaultValue != null)
         defaultMetadata = new PropertyMetadata(typeMetadata.DefaultValue);
     DependencyProperty dp = RegisterCommon(name, propertyType, ownerType, defaultMetadata, validateValueCallback);
     if (typeMetadata != null)
         dp.OverrideMetadata(ownerType, typeMetadata);
     else
         if (propertyType.IsValueType)
             dp.DefaultMetadata.DefaultValue = Activator.CreateInstance(propertyType);
     dp.ReadOnly = false;
     return dp;
 }
예제 #38
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;
        }
        /// <summary>
        ///     Register a Dependency Property
        /// </summary>
        /// <param name="name">Name of property</param>
        /// <param name="propertyType">Type of the property</param>
        /// <param name="ownerType">Type that is registering the property</param>
        /// <param name="typeMetadata">Metadata to use if current type doesn't specify type-specific metadata</param>
        /// <param name="validateValueCallback">Provides additional value validation outside automatic type validation</param>
        /// <returns>Dependency Property</returns>
        public static DependencyProperty Register(string name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata, ValidateValueCallback validateValueCallback)
        {
            RegisterParameterValidation(name, propertyType, ownerType);

            // Register an attached property
            PropertyMetadata defaultMetadata = null;
            if (typeMetadata != null && typeMetadata.DefaultValueWasSet())
            {
                defaultMetadata = new PropertyMetadata(typeMetadata.DefaultValue);
            }

            DependencyProperty property = RegisterCommon(name, propertyType, ownerType, defaultMetadata, validateValueCallback);

            if (typeMetadata != null)
            {
                // Apply type-specific metadata to owner type only
                property.OverrideMetadata(ownerType, typeMetadata);
            }

            return property;
        }
예제 #40
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;
        }
 public static FunctionalProperty Register(string name, Type propertyType, Type ownerType, FunctionalPropertyMetadata typeMetadata, ValidateValueCallback validateValueCallback)
 {
     return FunctionalPropertyManager.Instance.Register(name, propertyType, ownerType, typeMetadata, validateValueCallback);
 }
예제 #42
0
파일: Animatable.cs 프로젝트: JianwenSun/cc
        internal static DependencyProperty RegisterProperty(
            string name,
            Type propertyType,
            Type ownerType,
            object defaultValue,
            PropertyChangedCallback changed,
            ValidateValueCallback validate,
            bool isIndependentlyAnimated,
            CoerceValueCallback coerced)
        {
            // Override metadata for this particular object type. This defines
            // the methods that will be called when property actions (setting,
            // getting, invalidating) are taken for this specific object type.

            UIPropertyMetadata propertyMetadata;

            // If this property is animated using a property resource, we create
            // AnimatablePropertyMetadata instead of UIPropertyMetadata.

            if (isIndependentlyAnimated)
            {
                propertyMetadata = new IndependentlyAnimatedPropertyMetadata(defaultValue);
            }
            else
            {
                propertyMetadata = new UIPropertyMetadata(defaultValue);
            }

            propertyMetadata.PropertyChangedCallback = changed;

            if (coerced != null)
            {
                propertyMetadata.CoerceValueCallback = coerced;
            }

            // Register property with passed in default metadata.  The type of
            // defaultMetadata will determine whether this property is animatable.
            DependencyProperty dp = DependencyProperty.Register(
                name,
                propertyType,
                ownerType,
                propertyMetadata,
                validate);

            return dp;
        }
        private static void ValidateDefaultValueCommon(
            object defaultValue,
            Type propertyType,
            string propertyName,
            ValidateValueCallback validateValueCallback,
            bool checkThreadAffinity)
        {
            // Ensure default value is the correct type
            if (!IsValidType(defaultValue, propertyType))
            {
                throw new ArgumentException(SR.Get(SRID.DefaultValuePropertyTypeMismatch, propertyName));
            }

            // An Expression used as default value won't behave as expected since
            //  it doesn't get evaluated.  We explicitly fail it here.
            if (defaultValue is Expression )
            {
                throw new ArgumentException(SR.Get(SRID.DefaultValueMayNotBeExpression));
            }

            if (checkThreadAffinity)
            {
                // If the default value is a DispatcherObject with thread affinity
                // we cannot accept it as a default value. If it implements ISealable
                // we attempt to seal it; if not we throw  an exception. Types not
                // deriving from DispatcherObject are allowed - it is up to the user to
                // make any custom types free-threaded.

                DispatcherObject dispatcherObject = defaultValue as DispatcherObject;

                if (dispatcherObject != null && dispatcherObject.Dispatcher != null)
                {
                    // Try to make the DispatcherObject free-threaded if it's an
                    // ISealable.

                    ISealable valueAsISealable = dispatcherObject as ISealable;

                    if (valueAsISealable != null && valueAsISealable.CanSeal)
                    {
                        Invariant.Assert (!valueAsISealable.IsSealed,
                               "A Sealed ISealable must not have dispatcher affinity");

                        valueAsISealable.Seal();

                        Invariant.Assert(dispatcherObject.Dispatcher == null,
                            "ISealable.Seal() failed after ISealable.CanSeal returned true");
                    }
                    else
                    {
                        throw new ArgumentException(SR.Get(SRID.DefaultValueMustBeFreeThreaded, propertyName));
                    }
                }
            }


            // After checking for correct type, check default value against
            //  validator (when one is given)
            if ( validateValueCallback != null &&
                !validateValueCallback(defaultValue))
            {
                throw new ArgumentException(SR.Get(SRID.DefaultValueInvalid, propertyName));
            }
        }
예제 #44
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);
		}
예제 #45
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)");
		}
예제 #46
0
		public static DependencyProperty RegisterAttached(string name, Type propertyType, Type ownerType,
								  PropertyMetadata defaultMetadata,
								  ValidateValueCallback validateValueCallback)
		{
			DependencyProperty dp = new DependencyProperty(true, name, propertyType, ownerType,
								       defaultMetadata, validateValueCallback);
			DependencyObject.register(ownerType, dp);
			return dp;
		}
        private static DependencyProperty RegisterCommon(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata, ValidateValueCallback validateValueCallback)
        {
            FromNameKey key = new FromNameKey(name, ownerType);
            lock (Synchronized)
            {
                if (PropertyFromName.Contains(key))
                {
                    throw new ArgumentException(SR.Get(SRID.PropertyAlreadyRegistered, name, ownerType.Name));
                }
            }

            // Establish default metadata for all types, if none is provided
            if (defaultMetadata == null)
            {
                defaultMetadata = AutoGeneratePropertyMetadata( propertyType, validateValueCallback, name, ownerType );
            }
            else // Metadata object is provided.
            {
                // If the defaultValue wasn't specified auto generate one
                if (!defaultMetadata.DefaultValueWasSet())
                {
                    defaultMetadata.DefaultValue = AutoGenerateDefaultValue(propertyType);
                }

                ValidateMetadataDefaultValue( defaultMetadata, propertyType, name, validateValueCallback );
            }

            // Create property
            DependencyProperty dp = new DependencyProperty(name, propertyType, ownerType, defaultMetadata, validateValueCallback);

            // Seal (null means being used for default metadata, calls OnApply)
            defaultMetadata.Seal(dp, null);

            if (defaultMetadata.IsInherited)
            {
                dp._packedData |= Flags.IsPotentiallyInherited;
            }

            if (defaultMetadata.UsingDefaultValueFactory)
            {
                dp._packedData |= Flags.IsPotentiallyUsingDefaultValueFactory;
            }


            // Map owner type to this property
            // Build key
            lock (Synchronized)
            {
                PropertyFromName[key] = dp;
            }


            if( TraceDependencyProperty.IsEnabled )
            {
                TraceDependencyProperty.TraceActivityItem(
                    TraceDependencyProperty.Register,
                    dp,
                    dp.OwnerType );
            }


            return dp;
        }
        // Validate the default value in the given metadata
        private static void ValidateMetadataDefaultValue(
            PropertyMetadata defaultMetadata,
            Type propertyType,
            string propertyName,
            ValidateValueCallback validateValueCallback )
        {
            // If we are registered to use the DefaultValue factory we can
            // not validate the DefaultValue at registration time, so we
            // early exit.
            if (defaultMetadata.UsingDefaultValueFactory)
            {
                return;
            }

            ValidateDefaultValueCommon(defaultMetadata.DefaultValue, propertyType,
                propertyName, validateValueCallback, /*checkThreadAffinity = */ true);
        }
        private static DependencyProperty RegisterCommon(bool isAttached, string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata, ValidateValueCallback validateValueCallback, bool isReadOnly)
        {
            var comparer = GetComparer(propertyType);

            if (defaultMetadata != null && propertyType.IsValueType && defaultMetadata.DefaultValue == DependencyProperty.UnsetValue)
                defaultMetadata = defaultMetadata.OverrideMetadata(Activator.CreateInstance(propertyType), validateValueCallback, comparer);

            if (validateValueCallback == null)
            {
                if (isReadOnly && defaultMetadata == null)
                    defaultMetadata = GenerateDefaultMetadata(propertyType, comparer);
                else if (defaultMetadata != null)
                    defaultMetadata = defaultMetadata.OverrideMetadata(null, comparer);
            }
            else if (defaultMetadata != null)
            {
                var isDefaultValueValid = validateValueCallback(defaultMetadata.DefaultValue);
                if (!isDefaultValueValid)
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Default value for '{0}' property is not valid because ValidateValueCallback failed.", name));

                defaultMetadata = defaultMetadata.OverrideMetadata(validateValueCallback, comparer);
            }
            else
            {
                defaultMetadata = GenerateDefaultMetadata(propertyType, comparer);

                var isDefaultValueValid = validateValueCallback(defaultMetadata.DefaultValue);
                if (!isDefaultValueValid)
                    throw new ArgumentException(
                        string.Format(
                            CultureInfo.InvariantCulture,
                            "Cannot automatically generate a valid default value for property '{0}'. Specify a default value explicitly when owner type '{1}' is registering this DependencyProperty.",
                            name,
                            ownerType));

                defaultMetadata = defaultMetadata.OverrideMetadata(validateValueCallback, comparer);
            }

            DependencyProperty dp;

            // if we do not need extended metadata then fallback to System.Windows.PropertyMetadata.
            if (!isReadOnly && validateValueCallback == null
                && defaultMetadata != null && defaultMetadata.CoerceValueCallback == null && !HasSupportedFlags(defaultMetadata.Flags))
            {
                var simpleMetadata = new System.Windows.PropertyMetadata(defaultMetadata.DefaultValue, defaultMetadata.PropertyChangedCallback);
                dp = Register(isAttached, name, propertyType, ownerType, simpleMetadata);
            }
            else
            {
                dp = Register(isAttached, name, propertyType, ownerType, defaultMetadata);

                RememberMetadata(dp, defaultMetadata);
            }

            if (isReadOnly)
                readonlyDP.Add(dp);

            return dp;
        }
        /// <summary>
        /// Registers an attached property with the specified property name, property type, owner type, and property metadata.
        /// </summary>
        /// <param name="name">
        /// The name of the dependency property to register.
        /// </param>
        /// <param name="propertyType">
        /// The type of the property.
        /// </param>
        /// <param name="ownerType">
        /// The owner type that is registering the dependency property.
        /// </param>
        /// <param name="typeMetadata">
        /// Property metadata for the dependency property.
        /// </param>
        /// <param name="validateValueCallback">
        /// Callback that validates the new value for the dependency property.
        /// </param>
        /// <returns>
        /// A dependency property identifier that should be used to set the value of a public static readonly field in your class. That identifier is then used to reference the dependency property later, for operations such as setting its value programmatically or obtaining metadata.
        /// </returns>
        public static DependencyProperty RegisterAttached(string name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata, ValidateValueCallback validateValueCallback)
        {
#if WPF
			return DependencyProperty.RegisterAttached(name, propertyType, ownerType, typeMetadata, validateValueCallback);
#else
            return RegisterCommon(true, name, propertyType, ownerType, typeMetadata, validateValueCallback, false);
#endif
        }
예제 #51
0
        private static DependencyProperty RegisterCommon(string name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata, ValidateValueCallback validateValueCallback)
        {
            if (string.IsNullOrWhiteSpace(name))
                throw new ArgumentNullException("name");
            if (propertyType == null)
                throw new ArgumentNullException("propertyType");
            if (ownerType == null)
                throw new ArgumentNullException("ownerType");
            FromNameKey key = new FromNameKey(name, ownerType);
            if (_PropertyFromName.Contains(key))
                throw new ArgumentException("The property \"" + name + "\" is exists for \"" + ownerType.FullName + "\"");

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

            DependencyProperty dp = new DependencyProperty();
            dp.Name = name;
            dp.PropertyType = propertyType;
            dp.OwnerType = ownerType;
            dp.DefaultMetadata = typeMetadata;
            dp.ValidateValueCallback = validateValueCallback;

            _PropertyFromName.Add(key, dp);

            return dp;
        }
예제 #52
0
 public static DependencyPropertyKey RegisterAttachedReadOnly(string name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata, ValidateValueCallback validateValueCallback)
 {
     DependencyProperty dp = RegisterAttached(name, propertyType, ownerType, typeMetadata, validateValueCallback);
     dp.ReadOnly = true;
     DependencyPropertyKey key = new DependencyPropertyKey(dp);
     return key;
 }
예제 #53
0
 public static DependencyProperty RegisterAttached(string name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata, ValidateValueCallback validateValueCallback)
 {
     DependencyProperty dp = RegisterCommon(name, propertyType, ownerType, typeMetadata, validateValueCallback);
     if (propertyType.IsValueType && dp.DefaultMetadata.DefaultValue == null)
         dp.DefaultMetadata.DefaultValue = Activator.CreateInstance(propertyType);
     dp.ReadOnly = false;
     return dp;
 }
 internal DependencyPropertyKey(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata,
                                ValidateValueCallback validateValueCallback)
 {
   _dependencyProperty = DependencyProperty.Register(name, propertyType, ownerType, defaultMetadata,
                                                     validateValueCallback);
 }
        /// <summary>
        /// Registers a read-only dependency property with the specified property name, property type, owner type, and property metadata.
        /// </summary>
        /// <param name="name">
        /// The name of the dependency property to register.
        /// </param>
        /// <param name="propertyType">
        /// The type of the property.
        /// </param>
        /// <param name="ownerType">
        /// The owner type that is registering the dependency property.
        /// </param>
        /// <param name="typeMetadata">
        /// Property metadata for the dependency property.
        /// </param>
        /// <param name="validateValueCallback">
        /// Callback that validates the new value for the dependency property.
        /// </param>
        /// <returns>
        /// A dependency property identifier that should be used to set the value of a public static readonly field in your class. That identifier is then used to reference the dependency property later, for operations such as setting its value programmatically or obtaining metadata.
        /// </returns>
        public static DependencyPropertyKey RegisterReadOnly(string name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata, ValidateValueCallback validateValueCallback)
        {
#if WPF
			return DependencyProperty.RegisterReadOnly(name, propertyType, ownerType, typeMetadata, validateValueCallback);
#else
            var dp = RegisterCommon(false, name, propertyType, ownerType, typeMetadata, validateValueCallback, true);

            return new DependencyPropertyKey(dp);
#endif
        }
        /// <summary>
        ///  Simple registration, metadata, validation, and a read-only property
        /// key.  Calling this version restricts the property such that it can
        /// only be set via the corresponding overload of DependencyObject.SetValue.
        /// </summary>
        public static DependencyPropertyKey RegisterAttachedReadOnly(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata, ValidateValueCallback validateValueCallback)
        {
            RegisterParameterValidation(name, propertyType, ownerType);

            // Establish default metadata for all types, if none is provided
            if (defaultMetadata == null)
            {
                defaultMetadata = AutoGeneratePropertyMetadata( propertyType, validateValueCallback, name, ownerType );
            }

            //  We create a DependencyPropertyKey at this point with a null property
            // and set that in the _readOnlyKey field.  This is so the property is
            // marked as requiring a key immediately.  If something fails in the
            // initialization path, the property is still marked as needing a key.
            //  This is better than the alternative of creating and setting the key
            // later, because if that code fails the read-only property would not
            // be marked read-only.  The intent of this mildly convoluted code
            // is so we fail securely.
            DependencyPropertyKey authorizedKey = new DependencyPropertyKey(null);

            DependencyProperty property = RegisterCommon( name, propertyType, ownerType, defaultMetadata, validateValueCallback);

            property._readOnlyKey = authorizedKey;

            authorizedKey.SetDependencyProperty(property);

            return authorizedKey;
        }
        private DependencyProperty(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata, ValidateValueCallback validateValueCallback)
        {
            _name = name;
            _propertyType = propertyType;
            _ownerType = ownerType;
            _defaultMetadata = defaultMetadata;
            _validateValueCallback = validateValueCallback;

            Flags packedData;
            lock (Synchronized)
            {
                packedData = (Flags) GetUniqueGlobalIndex(ownerType, name);

                RegisteredPropertyList.Add(this);
            }

            if (propertyType.IsValueType)
            {
                packedData |= Flags.IsValueType;
            }

            if (propertyType == typeof(object))
            {
                packedData |= Flags.IsObjectType;
            }

            if (typeof(Freezable).IsAssignableFrom(propertyType))
            {
                packedData |= Flags.IsFreezableType;
            }

            if (propertyType == typeof(string))
            {
                packedData |= Flags.IsStringType;
            }

            _packedData = packedData;
        }
        /// <summary>
        ///  Simple registration, metadata, validation, and a read-only property
        /// key.  Calling this version restricts the property such that it can
        /// only be set via the corresponding overload of DependencyObject.SetValue.
        /// </summary>
        public static DependencyPropertyKey RegisterReadOnly(
            string name,
            Type propertyType,
            Type ownerType,
            PropertyMetadata typeMetadata,
            ValidateValueCallback validateValueCallback )
        {
            RegisterParameterValidation(name, propertyType, ownerType);

            PropertyMetadata defaultMetadata = null;

            if (typeMetadata != null && typeMetadata.DefaultValueWasSet())
            {
                defaultMetadata = new PropertyMetadata(typeMetadata.DefaultValue);
            }
            else
            {
                defaultMetadata = AutoGeneratePropertyMetadata(propertyType,validateValueCallback,name,ownerType);
            }

            //  We create a DependencyPropertyKey at this point with a null property
            // and set that in the _readOnlyKey field.  This is so the property is
            // marked as requiring a key immediately.  If something fails in the
            // initialization path, the property is still marked as needing a key.
            //  This is better than the alternative of creating and setting the key
            // later, because if that code fails the read-only property would not
            // be marked read-only.  The intent of this mildly convoluted code
            // is so we fail securely.
            DependencyPropertyKey authorizationKey = new DependencyPropertyKey(null); // No property yet, use null as placeholder.

            DependencyProperty property = RegisterCommon(name, propertyType, ownerType, defaultMetadata, validateValueCallback);

            property._readOnlyKey = authorizationKey;

            authorizationKey.SetDependencyProperty(property);

            if (typeMetadata == null )
            {
                // No metadata specified, generate one so we can specify the authorized key.
                typeMetadata = AutoGeneratePropertyMetadata(propertyType,validateValueCallback,name,ownerType);
            }

            // Authorize registering type for read-only access, create key.
            #pragma warning suppress 6506 // typeMetadata is never null, since we generate default metadata if none is provided.

            // Apply type-specific metadata to owner type only
            property.OverrideMetadata(ownerType, typeMetadata, authorizationKey);

            return authorizationKey;
        }
        /// <summary>
        ///     Register an attached Dependency Property
        /// </summary>
        /// <param name="name">Name of property</param>
        /// <param name="propertyType">Type of the property</param>
        /// <param name="ownerType">Type that is registering the property</param>
        /// <param name="defaultMetadata">Metadata to use if current type doesn't specify type-specific metadata</param>
        /// <param name="validateValueCallback">Provides additional value validation outside automatic type validation</param>
        /// <returns>Dependency Property</returns>
        public static DependencyProperty RegisterAttached(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata, ValidateValueCallback validateValueCallback)
        {
            RegisterParameterValidation(name, propertyType, ownerType);

            return RegisterCommon( name, propertyType, ownerType, defaultMetadata, validateValueCallback );
        }
        private static PropertyMetadata AutoGeneratePropertyMetadata(
            Type propertyType,
            ValidateValueCallback validateValueCallback,
            string name,
            Type ownerType)
        {
            // Default per-type metadata not provided, create
            object defaultValue = AutoGenerateDefaultValue(propertyType);

            // If a validator is passed in, see if the default value makes sense.
            if ( validateValueCallback != null &&
                !validateValueCallback(defaultValue))
            {
                // Didn't work - require the caller to specify one.
                throw new ArgumentException(SR.Get(SRID.DefaultValueAutoAssignFailed, name, ownerType.Name));
            }

            return new PropertyMetadata(defaultValue);
        }