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 ...

Get Universal Windows® Apps with XAML and C# 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.