[Home](../../) › [Metalama](../../metalama) › [Use Cases](../applications.md) › [Applications](classics.md) › [UI Patterns](ui.md) › Dependency Properties

# Dependency Properties

> Metalama.Patterns.Wpf is an open-source library for WPF, enhancing productivity by generating dependency properties without boilerplate code.

Canonical: https://postsharp.net/metalama/applications/dependency-property.html

Dependency properties enable advanced property behaviors such as data binding, animation, and styling. However, implementing dependency properties in WPF often requires writing repetitive and error-prone boilerplate code, which can slow down development and introduce bugs.

`Metalama.Patterns.Wpf` addresses this issue by allowing developers to generate dependency properties directly from C# automatic properties. This eliminates the need for boilerplate code and keeps your code cleaner and more maintainable.

`Metalama.Patterns.Wpf` is a production-ready, professionally supported, and open-source aspect library. <i class="supported no-tooltip"></i>

Available for WPF only.

## Example

```csharp
public partial class FancyTextBlock : UserControl
{
    public FancyTextBlock()
    {
        InitializeComponent();
    }

    // [<focus>]
    [Required]
    [DependencyProperty]
    // [<endfocus>]
    public string Text { get; set; } = "Hello, world.";

    // [<focus>]
    [DependencyProperty]
    // [<endfocus>]
    public Brush FancyBorderBrush { get; set; }

    public void OnFancyBorderBrushChanged() { /* Handle changes here. */}
}
```

## Benefits

* **Write less code**. Generate dependency properties from C# automatic properties without boilerplate code.
* **Reduce human errors**. Eliminate repetitive code that is prone to mistakes.
* **Improve maintainability**. Keep your codebase clean and easier to understand.
* **Fits existing projects**. Works with existing WPF projects without requiring major refactoring.
* **Customization**. Add validation rules or `OnPropertyChanged` callbacks tailored to your needs.

## Features

* Integrates with [Metalama.Patterns.Contracts](https://doc.metalama.net/patterns/contracts) to set validation rules.
* Fully customizable: add your own validation or `OnPropertyChanged` callbacks.

## Resources

* Blog post: [Implementing WPF Dependency Properties with Metalama](https://postsharp.net/blog/wpf-dependency-property-metalama).
* Reference documentation: [WPF Dependency Properties](https://doc.metalama.net/patterns/wpf/dependency-property).
* Source code: [Metalama.Patterns.Wpf](https://github.com/metalama/Metalama.Patterns/tree/HEAD/src/Metalama.Patterns.Wpf).
* NuGet package: [Metalama.Patterns.Wpf](https://www.nuget.org/packages/Metalama.Patterns.Wpf).

---

## Site navigation

- Previous: [Command](command.md)
- Next: [Memoization](memoization.md)
- Index of the whole site: [llms.txt](../../llms.txt)

