Prev | Current Page 277 | Next

Matthew MacDonald

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

The FrameworkPropertyMetadata object
and the validation callback are more interesting. You??™ll take a look at these details in the
following two sections.
Property Validation
The validation callback allows you to enforce the validation that you??™d normally add in the set
portion of a property procedure. The callback you supply must point to a method that accepts
an object parameter and returns a Boolean value. You return True to accept the object as valid
and False to reject it.
CHAPTER 6 n DEPENDENCY PROPERTIES AND ROUTED EVENTS 141
The validation of the FrameworkElement.Margin property isn??™t terribly interesting
because it relies on a Thickness.IsValid() method that has Friend accessibility (and so isn??™t
available to classes outside of the assembly where it??™s compiled). This method makes sure the
Thickness object is valid for its current use (representing a margin). For example, it may be
possible to construct a perfectly acceptable Thickness object that isn??™t acceptable for setting
the margin. One example is a Thickness object with negative dimensions. If the supplied
Thickness object isn??™t valid for a margin, the IsMarginValid property returns False:
Private Shared Function IsMarginValid(ByVal value As Object) As Boolean
Dim thickness1 As Thickness = CType(value, Thickness)
Return thickness1.


Pages:
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289