Dependency properties are registered by calling the DependencyProperty.Register method, whereas attached properties are registered by calling the DependencyProperty.RegisterAttached method. It takes four parameters—the actual name of the property, type of the property, type of the owner, and property metadata.
When you set the property to the control, as an attached property (extensions:TextBoxExtensions.SelectOnFocus="True", in our example), in the XAML, it registers it to the WPF property system during the instance load and fires the PropertyChangedCallback defined in the RegisterAttached method. In the preceding example, the OnSelectOnFocusChanged event will be called, which will register the GotFocus event on the associated TextBox control to perform the selection of the text.
Instead of a specific control such as TextBox, you can use UIElement to generalize the association. In this way, you can apply it to any control, by registering the attached...