Aspect that transforms a C# automatic property into a WPF dependency property. When applied to an automatic property in a class derived from DependencyObject, it generates the static DependencyProperty field and replaces the property accessors to use GetValue(DependencyProperty) and SetValue(DependencyProperty, Object).
Implements
Namespace: Metalama.Patterns.Wpf
Assembly: Metalama.Patterns.Wpf.dll
Syntax
[AttributeUsage(AttributeTargets.Property)]
public sealed class DependencyPropertyAttribute : Attribute, IAspect<IProperty>, IAspect, ICompileTimeSerializable, ITemplateProvider, IEligible<IProperty>, IHierarchicalOptionsProviderRemarks
The aspect supports the following features:
- Default values: Property initializers are used as the DefaultValue for the dependency property.
- Read-only properties: Properties with a private setter are registered as read-only dependency properties.
- Validation: A ValidateFoo method (where Foo is the property name) is automatically detected and called to validate values.
- Property changed callbacks: An OnFooChanged method is automatically detected and called after property changes.
- Contract integration: Contracts from Metalama.Patterns.Contracts (like [NotNull]) are enforced on the property.
Constructors
| Name | Description |
|---|---|
| DependencyPropertyAttribute() |
Properties
| Name | Description |
|---|---|
| InitializerProvidesDefaultValue | Gets or sets a value indicating whether the property initializer (if present) should be used to for DefaultValue. The default is true. |
| IsReadOnly | Gets or sets a value indicating whether the property should be registered as a read-only property. |
| PropertyChangedMethod | Gets or sets the name of the method that will be called when the the property value has changed. |
| RegistrationField | Gets or sets the name of the static readonly field that will be generated to expose the instance of the registered DependencyProperty. |
| ValidateMethod | Gets or sets the name of the method that validates the value of the property. |