HowWPF Uses Dependency Properties
As you??™ll discover throughout this book, dependency properties are required for a range of
WPF features. However, all of these features work through two key behaviors that every
dependency property supports??”change notification and dynamic value resolution.
As you??™ve already seen, when you change the value of a dependency property, a callback
is triggered. This callback is part of the low-level plumbing of WPF, and it takes care of updating
data bindings and firing triggers. Contrary to what you might expect, dependency
properties do not automatically fire events to let you know when a property value changes.
Instead, they trigger a protected method named OnPropertyChangedCallback(). This method
passes the information along to two WPF services (data binding and triggers) and calls the
PropertyChangedCallback, if one is defined.
CHAPTER 6 n DEPENDENCY PROPERTIES AND ROUTED EVENTS 149
In other words, if you want to perform an action when a property changes, you have two
choices??”you can create a binding that uses the property value (Chapter 15), or you can write
a trigger that automatically changes another property or starts an animation (Chapter 12).
However, dependency properties don??™t give you a general-purpose way to fire off some code
to respond to a property change.
Pages:
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304