Defining the Default Content Property
The Content
property is the default property of the ContentControl
. The ContentPropertyAttribute
specifies which property of a class can be interpreted as the main content property when the class is parsed by a XAML processor. This means that when, for example, a TextBlock
is placed as a nested element of a Button
, the TextBlock
is rendered within the button itself:
<Button> <TextBlock Text="Press me!" Foreground="Orange" /></Button>
To further illustrate, the built-in control template for the Button
control includes a Border
that contains a TemplateBinding
to the Content
property of the Button
, as shown in the following excerpt:
<Border> ...
Get Windows® Phone 8 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.