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
From the course: Microsoft XAML: 2 Content and Properties
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
The trouble with normal .NET properties for UI7m 56s
-
(Locked)
Explore the concept of dependency properties4m 33s
-
Use some dependency properties4m 53s
-
(Locked)
Order of precedence for dependency properties8m 56s
-
(Locked)
Explore the concept of attached properties4m 35s
-
(Locked)
Attached properties with the grid3m
-
(Locked)
Attached properties with the canvas3m 36s
-
(Locked)
Concepts of custom dependency properties3m 10s
-
(Locked)
Register the custom dependency property3m 20s
-
(Locked)
Use the custom dependency properties2m 1s
-
(Locked)
-