FontFamilyProperty. The shared constructor of TextElement registers the property,
but the shared constructors of TextBlock and Control simply reuse it by calling the
DependencyProperty.AddOwner() method:
TextBlock.FontFamilyProperty = _
TextElement.FontFmamilyProperty.AddOwner(GetType(TextBlock))
You can use the same technique when you create your own custom classes (assuming the
property is not already provided in the class you??™re inheriting from, in which case you get it for
free). You can also use an overload of the AddOwner() method that allows you to supply a validation
callback and a new FrameworkPropertyMetadata that will only apply to this new use of
the dependency property.
CHAPTER 6 n DEPENDENCY PROPERTIES AND ROUTED EVENTS 147
Reusing dependency properties can lead to some strange side effects in WPF, most
notably with styles. For example, if you use a style to set the TextBlock.FontFamily property
automatically, your style will also affect the Control.FontFamily property because behind the
scenes both classes use the same dependency property. You??™ll see this phenomenon in action
in Chapter 12.
Attached Dependency Properties
Chapter 2 introduced a special type of dependency property called an attached property. An
attached property is a dependency property, and it??™s managed by the WPF property system.
Pages:
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300