Prev | Current Page 284 | Next

Matthew MacDonald

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

Minimum Then
Return base1.Minimum
End If
Return value
End Function
In other words, if the value that??™s applied to the Maximum property is less than the
Minimum, the Minimum value is used instead to cap the Maximum. Notice that the
CoerceValueCallback passes two parameters??”the value that??™s being applied, and the
object to which it??™s being applied.
When the Value is set, a similar coercion takes place. The Value property is coerced so
that it can??™t fall outside of the range defined by the Minimum and Maximum, using this code:
Friend Shared Function ConstrainToRange(ByVal d As DependencyObject, _
ByVal value As Object) As Object
Dim newValue As Double = CType(value, Double)
Dim base1 As RangeBase = CType(d, RangeBase)
Dim minimum As Double = base1.Minimum
If newValue < minimum Then
Return minimum
End If
Dim maximum As Double = base1.Maximum
If newValue > maximum Then
Return maximum
End If
Return newValue
End Function
CHAPTER 6 n DEPENDENCY PROPERTIES AND ROUTED EVENTS 145
The Minimum property doesn??™t use value coercion at all. Instead, once it has been
changed, it triggers a PropertyChangedCallback that forces the Maximum and Value properties
to follow along by manually triggering their coercion:
Private Shared Sub OnMinimumChanged(ByVal d As DependencyObject, _
ByVal e As DependencyPropertyChangedEventArgs)
Dim base1 As RangeBase = CType(d, RangeBase)
.


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