public OverrideMetadata ( Type forType, System.Windows.PropertyMetadata typeMetadata ) : void | ||
forType | Type | |
typeMetadata | System.Windows.PropertyMetadata | |
return | void |
static MainWindow() { FrameworkPropertyMetadata metadata = new FrameworkPropertyMetadata(); metadata.Inherits = true; SpaceProperty = SpaceButton.SpaceProperty.AddOwner(typeof(MainWindow)); SpaceProperty.OverrideMetadata(typeof(Window), metadata); }
// static(정적) 생성자 static SpaceWindow() { // 메타데이터정의 FrameworkPropertyMetadata metadata = new FrameworkPropertyMetadata(); metadata.Inherits = true; //엘리먼트 트리를 통해 계승가능 // SpaceProperty에 소유자를 추가하고, 메타데이터를 오버라이딩(재정의) //이전에 등록된 의존 프로퍼티에 새로운 소유자를 추가할때 원래의 metadata가 적용되지 않으므로 반드시 그 자신의 //metadata를 생성 해야 한다. SpaceProperty = SpaceButton.SpaceProperty.AddOwner(typeof(SpaceWindow)); SpaceProperty.OverrideMetadata(typeof(SpaceWindow), metadata); }
/// <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>Registers a dependency property with the specified property name, property type, owner type, property metadata, and a value validation callback for the property. </summary> /// <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> /// <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">A reference to a callback that should perform any custom validation of the dependency property value beyond typical type validation.</param> public static DependencyProperty Register(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); } DependencyProperty dependencyProperty = RegisterCommon(name, propertyType, ownerType, defaultMetadata, validateValueCallback); if (typeMetadata != null) { dependencyProperty.OverrideMetadata(ownerType, typeMetadata); } return(dependencyProperty); }
public static DependencyProperty Register(string name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata, ValidateValueCallback validateValueCallback) { if (typeMetadata == null) { typeMetadata = new PropertyMetadata(); } DependencyProperty dp = new DependencyProperty(false, name, propertyType, ownerType, typeMetadata, validateValueCallback); DependencyObject.register(ownerType, dp); dp.OverrideMetadata(ownerType, typeMetadata); return(dp); }
/// <summary>Registers a read-only dependency property, with the specified property type, owner type, property metadata, and a validation callback. </summary> /// <returns>A dependency property key that should be used to set the value of a static read-only field in your class, which is then used to reference the dependency property later.</returns> /// <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">A reference to a user-created callback that should perform any custom validation of the dependency property value beyond typical type validation.</param> public static DependencyPropertyKey RegisterReadOnly(string name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata, ValidateValueCallback validateValueCallback) { RegisterParameterValidation(name, propertyType, ownerType); PropertyMetadata propertyMetadata = null; propertyMetadata = ((typeMetadata == null || !typeMetadata.DefaultValueWasSet()) ? AutoGeneratePropertyMetadata(propertyType, validateValueCallback, name, ownerType) : new PropertyMetadata(typeMetadata.DefaultValue)); DependencyPropertyKey dependencyPropertyKey = new DependencyPropertyKey(null); DependencyProperty dependencyProperty = RegisterCommon(name, propertyType, ownerType, propertyMetadata, validateValueCallback); dependencyProperty._readOnlyKey = dependencyPropertyKey; dependencyPropertyKey.SetDependencyProperty(dependencyProperty); if (typeMetadata == null) { typeMetadata = AutoGeneratePropertyMetadata(propertyType, validateValueCallback, name, ownerType); } dependencyProperty.OverrideMetadata(ownerType, typeMetadata, dependencyPropertyKey); return(dependencyPropertyKey); }
public static DependencyProperty Register(string name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata, ValidateValueCallback validateValueCallback) { if (typeMetadata == null) typeMetadata = new PropertyMetadata(); DependencyProperty dp = new DependencyProperty(false, name, propertyType, ownerType, typeMetadata, validateValueCallback); DependencyObject.register(ownerType, dp); dp.OverrideMetadata (ownerType, typeMetadata); return dp; }