Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

17. Dependency Properties > Creating Dependency Properties

Creating Dependency Properties

image

You don’t have to define the properties of your WPF classes as dependency properties. Plain Old POCO properties work just fine, but they don’t take advantage of the things that make WPF such a joy to work with. Would you go to a five-star restaurant and only have a glass of water?

It’s really not that difficult to make the magic happen. There are only four steps, and two of them are optional:

1 CREATE THE CLR PROPERTY

This is just a basic CLR property, but you must use GetValue() and SetValue() within the Get and Set accessors to make sure the CLR property works within the dependency property system.

2 CREATE THE CALLBACKS

This one’s optional, but if you need to coerce or validate the property values or want something to happen when the property changes, you’d create callback methods for those purposes. We’ll see how callbacks work at the end of this chapter.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint