.NET Framework Class Library
DependencyProperty..::.RegisterAttached Method (String, Type, Type)

Registers an attached property with the specified property name, property type, and owner type.

Namespace:  System.Windows
Assembly:  WindowsBase (in WindowsBase.dll)
Syntax

Visual Basic (Declaration)
Public Shared Function RegisterAttached ( _
    name As String, _
    propertyType As Type, _
    ownerType As Type _
) As DependencyProperty
Visual Basic (Usage)
Dim name As String
Dim propertyType As Type
Dim ownerType As Type
Dim returnValue As DependencyProperty

returnValue = DependencyProperty.RegisterAttached(name, _
    propertyType, ownerType)
C#
public static DependencyProperty RegisterAttached(
    string name,
    Type propertyType,
    Type ownerType
)
Visual C++
public:
static DependencyProperty^ RegisterAttached(
    String^ name, 
    Type^ propertyType, 
    Type^ ownerType
)
JScript
public static function RegisterAttached(
    name : String, 
    propertyType : Type, 
    ownerType : Type
) : DependencyProperty
XAML
You cannot use methods in XAML.

Parameters

name
Type: System..::.String
The name of the dependency property to register.
propertyType
Type: System..::.Type
The type of the property.
ownerType
Type: System..::.Type
The owner type that is registering the dependency property.

Return Value

Type: System.Windows..::.DependencyProperty
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.
Remarks

An attached property is a property concept defined by Extensible Application Markup Language (XAML). WPF implements attached properties as dependency properties. Because the WPF attached properties are dependency properties, they can have metadata applied that can be used by the general property system for operations such as reporting layout characteristics. For more information, see Attached Properties Overview.

For more information on dependency property registration, see DependencyProperty.

Examples

The following example registers an attached property on an abstract class using this RegisterAttached signature.

C#
public static readonly DependencyProperty IsBubbleSourceProperty = DependencyProperty.RegisterAttached(
  "IsBubbleSource",
  typeof(Boolean),
  typeof(AquariumObject2)
);
public static void SetIsBubbleSource(UIElement element, Boolean value)
{
    element.SetValue(IsBubbleSourceProperty, value);
}
public static Boolean GetIsBubbleSource(UIElement element)
{
    return (Boolean)element.GetValue(IsBubbleSourceProperty);
}
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0
See Also

Reference

Other Resources

Tags :


Community Content

Schneider
ownerType clarification
Note: The sample code fails to point out that it is defined within a public class called :
public class AquariumObject2
{
...
}

Without that class matching the ownerType paramter the DP wont work.
Tags :

Page view tracker