Prev | Current Page 359 | Next

Matthew MacDonald

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


Font Inheritance
When you set any of the font properties, the values flow through to nested objects. For example,
if you set the FontFamily property for the top-level window, every control in that window
gets the same FontFamily value (unless the control explicitly sets a different font). This feature
is similar to the Windows Forms concept of ambient properties, but the underlying plumbing
is different. It works because the font properties are dependency properties, and one of the
features that dependency properties can provide is property value inheritance??”the magic
that passes your font settings down to nested controls.
It??™s worth noting that property value inheritance can flow through elements that don??™t
even support that property. For example, imagine you create a window that holds a
StackPanel, inside of which are three Label controls. You can set the FontSize property of the
window because the Window class derives from the Control class. You can??™t set the FontSize
property for the StackPanel because it isn??™t a control. However, if you set the FontSize property
of the window, your property value is still able to flow ???through??? the StackPanel to get to your
labels inside and change their font sizes.
Along with the font settings, several other base properties use property value inheritance.


Pages:
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371