예제 #1
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;
 }
예제 #2
0
 public static DependencyProperty RegisterAttached(string name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata)
 {
     return RegisterAttached(name, propertyType, ownerType, typeMetadata, null);
 }
예제 #3
0
        private void OverrideMetadataCore(Type forType, PropertyMetadata typeMetadata)
        {
            typeMetadata.Apply(this, forType);

            DefaultMetadata.Merge(typeMetadata, this);
        }
예제 #4
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");
     if (key.Property != this)
         throw new InvalidOperationException("Readonly property key not authorized.");
     OverrideMetadataCore(forType, typeMetadata);
 }
예제 #5
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;
        }
예제 #6
0
 public DependencyProperty AddOwner(Type ownerType, PropertyMetadata typeMetadata)
 {
     if (ownerType == null)
         throw new ArgumentNullException("ownerType");
     DefaultMetadata.Apply(this, PropertyType);
     DependencyProperty dp = RegisterCommon(Name, PropertyType, ownerType, typeMetadata, ValidateValueCallback);
     dp.DefaultMetadata.Merge(DefaultMetadata, dp);
     dp.ReadOnly = ReadOnly;
     return dp;
 }
예제 #7
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("Readonly property override not allowed.");
     OverrideMetadataCore(forType, typeMetadata);
 }
예제 #8
0
 public static DependencyPropertyKey RegisterReadOnly(string name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata, ValidateValueCallback validateValueCallback)
 {
     DependencyProperty dp = Register(name, propertyType, ownerType, typeMetadata, validateValueCallback);
     dp.ReadOnly = true;
     DependencyPropertyKey key = new DependencyPropertyKey(dp);
     return key;
 }
예제 #9
0
 public static DependencyPropertyKey RegisterReadOnly(string name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata)
 {
     return RegisterReadOnly(name, propertyType, ownerType, typeMetadata);
 }
예제 #10
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;
 }
예제 #11
0
 protected virtual void OnMerge(PropertyMetadata baseMetadata, DependencyProperty dp)
 {
 }
예제 #12
0
 internal void Merge(PropertyMetadata baseMetadata, DependencyProperty dp)
 {
     CheckFrozen();
     if (_DefaultValue == null)
         _DefaultValue = baseMetadata._DefaultValue;
     if (_PropertyChangedCallback == null)
         _PropertyChangedCallback = baseMetadata._PropertyChangedCallback;
     if (_CoerceValueCallback == null)
         _CoerceValueCallback = baseMetadata._CoerceValueCallback;
     OnMerge(baseMetadata, dp);
 }