DependencyProperty.RegisterAttached method
Registers an attached dependency property with the specified property name, property type, owner type, and property metadata for the property.
Syntax
public static DependencyProperty RegisterAttached( string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata )
Parameters
- name
-
Type: System.String [.NET] | Platform::String [C++]
The name of the dependency property to register.
- propertyType
-
Type: System.Type [.NET] | TypeName [C++]
The type of the property.
- ownerType
-
Type: System.Type [.NET] | TypeName [C++]
The owner type that is registering the dependency property.
- defaultMetadata
-
Type: PropertyMetadata
A property metadata instance. This can contain a PropertyChangedCallback implementation reference.
Return value
Type: DependencyProperty
A dependency property identifier that should be used to set the value of a public static read-only field in your class. That identifier is then used to reference the attached property later, for operations such as setting its value programmatically or attaching a Binding.
Remarks
Tip If you are programming using a Microsoft .NET language (C# or Microsoft Visual Basic), the TypeName type projects as System.Type. When programming using C#, it is common to use the typeof operator to get references to the System.Type of a type. In Visual Basic, use GetType.
Examples
This example defines a class that derives from DependencyObject, and defines an attached property along with the identifier field. The scenario for this class is that it is a service class that declares an attached property that other UI elements can set in XAML, and the service potentially acts on the attached property values on those UI elements at run time. For more examples, see Custom attached properties.
public abstract class AquariumServices : DependencyObject
{
public enum Bouyancy {Floats,Sinks,Drifts}
public static readonly DependencyProperty BouyancyProperty = DependencyProperty.RegisterAttached(
"Bouyancy",
typeof(Bouyancy),
typeof(AquariumServices),
new PropertyMetadata(Bouyancy.Floats)
);
public static void SetBouyancy(DependencyObject element, Bouyancy value)
{
element.SetValue(BouyancyProperty, value);
}
public static Bouyancy GetBouyancy(DependencyObject element)
{
return (Bouyancy)element.GetValue(BouyancyProperty);
}
}
Requirements
|
Minimum supported client | Windows 8 |
|---|---|
|
Minimum supported server | Windows Server 2012 |
|
Namespace |
|
|
Metadata |
|
See also
- DependencyProperty
- Custom attached properties
- Dependency properties overview
- Attached properties overview
Build date: 1/31/2013
