Showing formatted text in a TextBlock in Windows Phone apps

Here is a quick tip on Windows Phone development. If you want to show formatted text i.e. text having multiple styles or colors in a single line in your windows phone apps then you can easily do so with a TextBlock. Example below shows how you can show a normal text along with a highlighted text and a bold text all in the same line in a TextBlock. Text Wrapping also comes for free as it is handled by TextBlock itself.

Here is the XAML:

<TextBlock TextWrapping="Wrap" Margin="12">
 <Run FontWeight="Light" Text="Normal Text"/>
 <Run Foreground="Aqua" Text=" Highlighted Text"/>
 <Run FontWeight="Bold" Text=" Bold text"/>
 <Run FontWeight="Light" Text=" Normal Text"/>

Here is the result:

Formatted Text in WindowsPhone App

In case you want databinding to work with the multiple formatted text runs then kindly see the following link:

Filed under: Windows Phone DevelopmentTagged with:

You may also like..

About the author

Kanishk Kunal

Kanishk is a professional developer who builds apps and websites for both fun & profit. He spends most of his time punching his keyboard and swiping his smartphone.

No comment yet, add your voice below!

Add a Comment

Your email address will not be published. Required fields are marked *

Comment *

Email *