Prev | Current Page 286 | Next

Matthew MacDonald

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


After the second line of code, the Value property is coerced to 1 (because initially the
Maximum property is set to the default value 1). But something remarkable happens when
you reach the fourth line of code. When the Maximum property is changed, it triggers coercion
on both the Minimum and Value properties. This coercion acts on the values you
specified originally. In other words, the local value of 100 is still stored by the WPF dependency
property system, and now that it??™s an acceptable value, it can be applied to the Value
property. Thus, after this single line of code executes, two properties have changed. Here??™s
a closer look at what??™s happening:
CHAPTER 6 n DEPENDENCY PROPERTIES AND ROUTED EVENTS 146
Dim bar As New ScrollBar()
bar.Value = 100
' (Right now bar.Value returns 1.)
bar.Minimum = 1
' (bar.Value still returns 1.)
bar.Maximum = 200
' (Now now bar.Value returns 100.)
This behavior persists no matter when you set the Maximum property. For example, if you
set a Value of 100 when the window loads, and set the Maximum property later when the user
clicks a button, the Value property is still restored to its rightful value of 100 at that point.
(The only way to prevent this from taking place is to set a different value or remove the local
value that you??™ve applied using the ClearValue() method that all elements inherit from
DependencyObject.


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