Export (0) Print
Expand All

DependencyProperty.RegisterAttached Method (String, Type, Type, PropertyMetadata, ValidateValueCallback)

Registers an attached property with the specified property type, owner type, property metadata, and value validation callback for the property.

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

public static DependencyProperty RegisterAttached (
	string name,
	Type propertyType,
	Type ownerType,
	PropertyMetadata defaultMetadata,
	ValidateValueCallback validateValueCallback
)
public static DependencyProperty RegisterAttached (
	String name, 
	Type propertyType, 
	Type ownerType, 
	PropertyMetadata defaultMetadata, 
	ValidateValueCallback validateValueCallback
)
public static function RegisterAttached (
	name : String, 
	propertyType : Type, 
	ownerType : Type, 
	defaultMetadata : PropertyMetadata, 
	validateValueCallback : ValidateValueCallback
) : DependencyProperty
You cannot use methods in XAML.

Parameters

name

The name of the dependency property to register.

propertyType

The type of the property.

ownerType

The owner type that is registering the dependency property.

defaultMetadata

Property metadata for the dependency property. This can include the default value as well as other characteristics.

validateValueCallback

A reference to a callback that should perform any custom validation of the dependency property value beyond typical type validation.

Return Value

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.

An attached property is a property concept defined by Extensible Application Markup Language (XAML). WPF implements attached properties as dependency properties, but that aspect is not a strict requirement to be an attached property. 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.

The following example registers an attached property on an abstract class using this RegisterAttached signature. This attached property is an enumeration type property, and the registration adds a validation callback to verify that the provided value is a value of the enumeration.

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);
}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft