Quickstart: displaying text (Windows Store apps using C#/VB/C++ and XAML)
The XAML framework for Windows Store apps using C++, C#, or Visual Basic provides several controls for rendering text, and a set of properties for formatting the text. The controls for displaying read-only text are TextBlock and RichTextBlock. This quickstart shows you how to use TextBlock controls to display text.
Roadmap: How does this topic relate to others? See:
We assume that you can create a basic Windows Store app using C++, C#, or Visual Basic. For instructions on adding a control, see Quickstart: Adding controls and handling events.
TextBlock is the primary control for displaying read-only text in Windows Store apps using C++, C#, or Visual Basic. You can display text in a TextBlock control using its Text property. This XAML shows how to define a TextBlock control and set its Text property to a string.
You can also display a series of strings in a TextBlock, where each string has different formatting. You can do this by using a Run element to display each string with its formatting and by separating each Run element with a LineBreak element.
<TextBlock FontFamily="Arial" Width="400" Text="Sample text formatting runs"> <LineBreak/> <Run Foreground="LightGray" FontFamily="Courier New" FontSize="24"> Courier New 24 </Run> <LineBreak/> <Run Foreground="Teal" FontFamily="Times New Roman" FontSize="18" FontStyle="Italic"> Times New Roman Italic 18 </Run> <LineBreak/> <Run Foreground="SteelBlue" FontFamily="Verdana" FontSize="14" FontWeight="Bold"> Verdana Bold 14 </Run> </TextBlock>
Here's the result.
You learned how to create TextBlock controls to display text in your app.
For more code examples that show these controls, see the XAML text display sample.
Build date: 11/19/2013