---
title: "A simpler, conventions based DependencyProperty structure for silverlight using CustomControlBase"
url: "https://osherove.com/blog/2009/5/27/a-simpler-conventions-based-dependencyproperty-structure-for.md"
canonical: "https://osherove.com/blog/2009/5/27/a-simpler-conventions-based-dependencyproperty-structure-for.html"
published: "2009-05-27T05:44:27"
updated: "2009-05-27T05:44:27"
tags: [".NET", "Silverlight"]
author: "Roy Osherove"
description: "Having stated to look into silverlight not long ago, I was totally put off by the horridness that is DependencyProperties, and how you implement them: You need to declare a static property that is registered at the type…"
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# A simpler, conventions based DependencyProperty structure for silverlight using CustomControlBase

By Roy Osherove May 27, 2009 In [.NET](https://osherove.com/blog/category/net), [Silverlight](https://osherove.com/blog/category/silverlight)

**Historical article** · Originally published May 27, 2009; technical details may be outdated.

Having stated to look into silverlight not long ago, I was totally put off by the horridness that is DependencyProperties, and how you implement them:

- You need to declare a static property that is registered at the type initialization phase
- you need to have a “regular” property that calls getvalue and setvalue with that property
- if you want to handle changes you need to registed a specific callback in the dependency declaration
- the same goes for default value

yuck.

So here’s what I came up with. [It’s a simple base class you can use in your silverlight projects](http://pastie.org/491270), and inherit your custom control from. Once you do it, you can write DependencyProperties like this:

![image](https://osherove.com/img/wb/2d14875a_weblogs.asp.net_blogs_rosherove_image_thumb_02AECB7C.png)

the things to note here:

- You inherit from CustomControlBase
- The On\[PropertyName\]Changed will be registered automatically based on its name (Convention based work)
- You call GetDPValue and SetDPValue instead of GetValue and SetValue
- You set the DefaultValue using an attribute (in System.ComponentModel)
- You can omit the callback method if you want.

## More in .NET

[All posts in .NET](https://osherove.com/blog/category/net)

- Jun 1, 2009

    ### [Review: CryptoLicensing for .NET](https://osherove.com/blog/2009/6/1/review-cryptolicensing-for-net.html)

- May 31, 2009

    ### [Daily news blogs about .NET and related creatures](https://osherove.com/blog/2009/5/31/daily-news-blogs-about-net-and-related-creatures.html)

- May 27, 2009

    ### [Fix: Requested registry access is not allowed error when creating silverlight project in visual studio 2008](https://osherove.com/blog/2009/5/27/fix-requested-registry-access-is-not-allowed-error-when-crea.html)

- Apr 27, 2009

    ### [Upcoming travel: SEConf, NDC](https://osherove.com/blog/2009/4/27/upcoming-travel-seconf-ndc.html)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
