Friday, December 9, 2011

WPF: Rich TextBlock XAML example

"The TextBlock was designed specifically for the purpose of showing small amounts of flowing rich text to the user.
It is the perfect element for displaying instructions or summary information."


Usage example
I have a program that users can communicate with each other. I wish to add the feature of bold, colored, line-breaking and icons to that chat.

Here is an example I've found to illustrate it:













Example
Code Snippet
  1. <TextBlock FontSize="10" TextWrapping="Wrap" >
  2.     <Image Stretch="UniformToFill" Width="32" Height="32" Source="http://upload.wikimedia.org/wikipedia/en/b/b0/Avatar-Teaser-Poster.jpg" Margin="2 2 2 2" />
  3.                     <Bold><Italic FontSize="12" Foreground="DarkGreen">ShloEmi:</Italic></Bold><LineBreak />
  4.     <Bold><Italic FontSize="14" Foreground="BlueViolet">H</Italic></Bold>ave  fun with <Bold>TextBlock's</Bold>.<LineBreak />
  5.     <AccessText Foreground="Blue">It's easy when you have an example </AccessText> <Image Source="http://upload.wikimedia.org/wikipedia/commons/thumb/8/85/Smiley.svg/50px-Smiley.svg.png" Width="16" Height="16"></Image>
  6. </TextBlock>

Result








Have fun...

No comments:

Post a Comment