Creating a custom dependency property requires writing code that registers the property with the dependency system. This tutorial shows how to correctly register a new dependency property and create a .NET property wrapper.
- [Instructor] I have this custom user control…that I created, and we'll use it to demonstrate…how to create your own custom dependency property.…The purpose of this control is to draw stars on the screen,…and it has different shaped stars.…You can have a five-point star, which you can see here,…and also has a six-point star.…So the dependency property that I want to create…is for changing the number of points on the star.…To do that I need to go to my code behind.…And we'll talk about the first rule.…If you're going to create a dependency property,…your class, in my case this StarShape class,…must derive from DependencyObject.…
Now the good news is user control derives from…DependencyObject, and most WPF elements have this class…somewhere in their class hierarchy.…The next step is to declare a variable to represent…the dependency property, and this is gonna be…of type DependencyProperty.…So I'm doing this on line 33.…So the name of my property is PointsProperty,…and I'm using the Microsoft naming standard…where I use the word Property at the end.…
- What does content mean in XAML?
- Using dotPeek to show property values for XAML elements
- Expressing content as objects, lists, or dictionaries in XAML vs. code
- Exploring dependency and attached properties
- Working with attached properties in the grid and canvas
- Using custom dependency properties