Prev | Current Page 285 | Next

Matthew MacDonald

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

..
base1.CoerceValue(RangeBase.MaximumProperty)
base1.CoerceValue(RangeBase.ValueProperty)
End Sub
Similarly, once the Maximum has been set and coerced, it manually coerces the Value
property to fit:
Private Shared Sub OnMaximumChanged(ByVal d As DependencyObject, _
ByVal e As DependencyPropertyChangedEventArgs)
Dim base1 As RangeBase = CType(d, RangeBase)
...
base1.CoerceValue(RangeBase.ValueProperty)
base1.OnMaximumChanged(CType(e.OldValue, Double), _
CType(e.NewValue, Double))
End Sub
The end result is that if you set conflicting values, the Minimum takes precedence, the
Maximum gets its say next (and may possibly be coerced by the Minimum), and then the
Value is applied (and may be coerced by both the Maximum and Minimum).
The goal of this somewhat confusing sequence of steps is to ensure that the ScrollBar
properties can be set in various orders without causing an error. This is an important consideration
for initialization, such as when a window is being created for a XAML document. All
WPF controls guarantee that their properties can be set in any order, without causing any
change in behavior.
A careful review of the previous code calls this goal into question. For example, consider
this code:
Dim bar As New ScrollBar()
bar.Value = 100
bar.Minimum = 1
bar.Maximum = 200
When the ScrollBar is first created, Value is 0, Minimum is 0, and Maximum is 1.


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