Prev | Current Page 283 | Next

Matthew MacDonald

"Pro WPF with VB 2008: Windows Presentation Foundation with .NET 3.5"

Register() method) and the
PropertyChangedCallback and CoerceValueCallback (which you can supply as constructor
arguments when creating the FrameworkPropertyMetadata object). Here??™s how all the pieces
come into play:
CHAPTER 6 n DEPENDENCY PROPERTIES AND ROUTED EVENTS 144
??? First, the CoerceValueCallback method has the opportunity to modify the supplied
value (usually, to make it consistent with other properties) or return
DependencyProperty.UnsetValue, which rejects the change altogether.
??? Next, the ValidateValueCallback is fired. This method returns True to accept a value as
valid, or False to reject it. Unlike the CoerceValueCallback, the ValidateValueCallback
does not have access to the actual object on which the property is being set, which
means you can??™t examine other property values.
??? Finally, if both these previous stages succeed, the PropertyChangedCallback is
triggered. At this point, you can raise a change event if you want to provide notification
to other classes.
The CoerceValueCallback is the preferred way to deal with interrelated properties. For
example, the ScrollBar provides Maximum, Minimum, and Value properties, all of which are
inherited from the RangeBase class. When the Maximum is set, it??™s coerced so that it can??™t be
less than the Minimum:
Private Shared Function CoerceMaximum(ByVal d As DependencyObject, _
ByVal value As Object) As Object
Dim base1 As RangeBase = CType(d, RangeBase)
If CType(value, Double) < base1.


Pages:
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295