Gets or sets the text contents of a TextBlock.
Assembly: System.Windows (in System.Windows.dll)
Dependency property identifier field: TextProperty
The TextBlock object is the primary text element for displaying text in Silverlight-based applications.
A TextBlock can be thought of as having two object models:
A representation as a property, which represents only string content. (The text has no formatting other than the formatting that is declared at the TextBlock level.)
A representation as an InlineCollection. The collection contains primarily Run objects, each of which can declare its own formatting properties such as FontSize. The 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 value, you will flatten the previous InlineCollection content and replace it with a single unformatted Run with the new text.
When you set text in a TextBlock, it is not necessary in XAML to explicitly specify the property. You can put text in the TextBlock container as its content, or inner text, as in the following example:
Leading or trailing whitespace is not preserved when you set the property.