Google Formatted text in a TextBlock in Windows Phone C# | SubramanyamRaju Xamarin & Windows App Dev Tutorials

Wednesday 26 February 2014

Formatted text in a TextBlock in Windows Phone C#

You can also display a series of strings in a TextBlock, where each string has a 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.
The following XAML shows how to define several differently formatted text strings in a TextBlock by using Run objects separated with a LineBreak.

<Grid>
    <TextBlock FontFamily="Arial" Width="400" >
        <LineBreak/>
        <Run Foreground="Maroon" FontFamily="Courier New" FontSize="40">
            Courier New 24
        </Run>
        <LineBreak/>
        <Run Foreground="Teal" FontFamily="Times New Roman" FontSize="30" FontStyle="Italic">
            Times New Roman Italic 18
        </Run>
        <LineBreak/>
        <Run Foreground="SteelBlue" FontFamily="Verdana" FontSize="20" FontWeight="Bold">
            Verdana Bold 14
        </Run>
    </TextBlock>
</Grid>
The following illustration shows the result of the previous XAML.
TextBlock - Text formatting
In case you want databinding to work with the multiple formatted text runs then kindly see the following link: http://stackoverflow.com/questions/5253622/databinding-textblock-runs-in-silverlight-wp7
Source: MSDN

Have a nice day by 

No comments:

Post a Comment

Search Engine Submission - AddMe