Prev | Current Page 280 | Next

Matthew MacDonald

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

Even if you don??™t set a dependency property directly, it may already
have a value??”perhaps one that??™s applied by a binding, style, or animation, or one that??™s inherited
through the element tree. (You??™ll learn more about these rules of precedence a bit later in
the section ???How WPF Uses Dependency Properties.???) However, as soon as you set the value
directly, it overrides all these other influences.
At some point later, you may want to remove your local value setting and let the property
value be determined as though you never set it. Obviously, you can??™t accomplish this by
setting a new value. Instead, you need to use another method that??™s inherited from
DependencyObject: the ClearValue() method. Here??™s how it works:
myElement.ClearValue(FrameworkElement.MarginProperty)
Property Metadata
Technically, you don??™t need to create a FrameworkPropertyMetadata object because there??™s an
overload of the Dependency.Register() method that doesn??™t require one. However, you need
the FrameworkPropertyMetadata object if you want to configure any one of a number of
dependency property features.
nNote In the Windows Forms platform, the same function is provided using ordinary .NET attributes from
several namespaces. Although you??™ll still use some attributes with WPF elements (for example, to attach
custom type converters), the system is clearer because several important options are grouped into the
FrameworkPropertyMetadata class.


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