O'Reilly logo

XAML Unleashed by Adam Nathan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Respecting the Target Control’s Properties

There’s a bit of a problem with the custom template in Figure 18.4. Any Button it is applied to will look the same, no matter what the values of its properties are. Most notably, the right Button in Figure 18.4 has "With Custom Template" as its content, but it never gets displayed. If you’re creating a control template that’s meant to be broadly reusable, you need to do some work to respect various properties of the target control (sometimes called the templated parent).

Respecting ContentControl’s Content Property

The key to inserting property values from the target element inside a control template is a specialized form of data binding. You can set a property to the markup extension value:

{TemplateBinding ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required