| title | ms.custom | ms.date | ms.prod | ms.reviewer | ms.suite | ms.technology | ms.tgt_pltfrm | ms.topic | helpviewer_keywords | ms.assetid | caps.latest.revision | author | ms.author | manager | |||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
How to: Register an Attached Property |
03/30/2017 |
.net-framework |
|
article |
|
eb47bd94-0451-4f8d-8fb6-95f7812ac05b |
12 |
dotnet-bot |
dotnetcontent |
wpickett |
How to: Register an Attached Property
This example shows how to register an attached property and provide public accessors so that you can use the property in both [!INCLUDETLA#tla_xaml] and code. Attached properties are a syntax concept defined by [!INCLUDETLA#tla_xaml]. Most attached properties for [!INCLUDETLA2#tla_winclient] types are also implemented as dependency properties. You can use dependency properties on any xref:System.Windows.DependencyObject types.
Example
The following example shows how to register an attached property as a dependency property, by using the xref:System.Windows.DependencyProperty.RegisterAttached%2A method. The provider class has the option of providing default metadata for the property that is applicable when the property is used on another class, unless that class overrides the metadata. In this example, the default value of the IsBubbleSource property is set to false.
The provider class for an attached property (even if it is not registered as a dependency property) must provide static get and set accessors that follow the naming convention Set[AttachedPropertyName] and Get[AttachedPropertyName]. These accessors are required so that the acting [!INCLUDETLA2#tla_xaml] reader can recognize the property as an attribute in [!INCLUDETLA2#tla_xaml] and resolve the appropriate types.
[!code-csharpWPFAquariumSln#RegisterAttachedBubbler] [!code-vbWPFAquariumSln#RegisterAttachedBubbler]
See Also
xref:System.Windows.DependencyProperty
Dependency Properties Overview
Custom Dependency Properties
How-to Topics