Working with attached properties
An attached property is a kind of dependency
property which is intended to be used as a global property type and is settable on any object. It does not have conventional property wrapper and can still be used to receive notification of a value change. Unlike dependency properties, attached properties are not defined in the same class where they are used.
The main purpose of using attached properties is to allow different child elements to specify unique values of a property, which is actually defined in a parent element. For example, you can use Grid.Row
, Grid.Column
in any child elements of the Grid
panel. Similarly, the Canvas.Left
, Canvas.Top
attached properties are used in any child elements of a Canvas
panel.
In this recipe, we will learn how to create an Attached
property and perform the operation from a different class.
Getting ready
First, create a new project called CH04.AttachedPropertyDemo
, based on the WPF application project type.
How to do it...
Now...