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; }
public static DependencyProperty RegisterAttached(string name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata) { return RegisterAttached(name, propertyType, ownerType, typeMetadata, null); }
private void OverrideMetadataCore(Type forType, PropertyMetadata typeMetadata) { typeMetadata.Apply(this, forType); DefaultMetadata.Merge(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"); if (key == null) throw new ArgumentNullException("key"); if (key.Property != this) throw new InvalidOperationException("Readonly property key not authorized."); OverrideMetadataCore(forType, typeMetadata); }
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; }
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; }
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); }
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; }
public static DependencyPropertyKey RegisterReadOnly(string name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata) { return RegisterReadOnly(name, propertyType, ownerType, typeMetadata); }
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; }
protected virtual void OnMerge(PropertyMetadata baseMetadata, DependencyProperty dp) { }
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); }