How to format texts of TextBlock using xaml in Windows Phone

Sometime you may want to write formatted text in your app to give more pleasant for an eye of users or to get more attention from the user, sometime you may also want to display text where first few parts should be bold, colorful with big font size and rest part is normal.

As for example :

Hello World ! I am learning how to format texts 

Here, we can see a sentence is mixed with a different format of texts. Some part is in Bold and Colorful, some part is normal and some part is bold with underline as shown in below pic.

RRK-wptextblock

from above figure, we can see that ¬†“Hello World” is in Red Color, “I am learning” is in italic font and “How to format text” is in Bold with underline text style.

Code for format TextBlock

To show formatted text i.e. text having multiple styles or colors in a single line in your windows phone apps then we can easily do so with a TextBlock

 

We can also change the font style of selected part of a line by using FontFamily property of TextBlock.

 

Here is the output of above code.

rrk-wptextblock2

Leave a Reply