From the course: Microsoft XAML: 2 Content and Properties

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Register the custom dependency property

Register the custom dependency property

From the course: Microsoft XAML: 2 Content and Properties

Start my 1-month free trial

Register the custom dependency property

- [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…

Contents