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

Text Content

The big secret of TextBlock is that its Text property (of type string) is not its content property. Instead, it is a property called Inlines that is a collection of Inline objects. Although the following TextBlock gives the same result as setting the Text property, you’re really setting Inlines instead:

<!-- TextBlock.Inlines is being set here: --><TextBlock>Text in a TextBlock</TextBlock>

A type converter makes the value resemble a simple string, but it’s actually a collection with one Inline-derived element called Run. Therefore, the preceding XAML is equivalent to the following:

<TextBlock><Run Text="Text in a TextBlock"/></TextBlock>

which is also equivalent to the following ...

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