Gets the collection of inline text elements within a TextBlock.
Assembly: System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.
A TextBlock can be thought of as having two object models:
A representation as an InlineCollection. The collection contains primarily Run objects, each of which can declare its own formatting properties such as FontSize. The Text property returns a value (the appended text of all Run elements in the InlineCollection). However, the returned value does not include any formatting that has been applied to the Run elements. If the InlineCollection is created from XAML as inner text of a TextBlock object element, or if it is created by setting the Text property, the InlineCollection contains a single Run that contains that text.
You can work with either object model. However, if the text consists of series of text elements with individual formatting in an InlineCollection, and if you modify the text by appending to the Text value, you will flatten the previous InlineCollection content and replace it with a single unformatted Run with the new text.
A TextBlock can contain mixed inner text and inline elements. In this case, each of the inner text sections is parsed and converted into a Run, rather than being preserved as true inner text of the TextBlock. Because of this behavior, you can freely mix inner text and child elements, which is not typically permitted in XAML. Inner text of a TextBlock can appear before or after any child elements of a TextBlock. Multiple blocks of inner text can be mixed with multiple child elements.
The InlineCollection is created implicitly by parsing the TextBlock content. Setting as an explicit property element is permitted in XAML. However, this is not recommended, because even XML white space is interpreted as possible content of the TextBlock. If any content is detected, the parser populates the implicit InlineCollection by using that content as an initial Run. (Because setting the property is not recommended, property element syntax is not illustrated in the syntax section.) If you define after setting the property, it is interpreted as an attempt to set twice. The only way to specify as a property element would be if there were no white space at all between the TextBlock object element and property element.
The XAML syntax for is an example of an implicit collection syntax, where you omit an actual InlineCollection object element. Instead, you include one or more inline types (Run and LineBreak elements) as child elements of a TextBlock. In addition to the implicit collection syntax of inline elements, TextBlock also lets you specify content as inner text, or by setting the value of Text by using a string. For more information, see the TextBlock class description.