SilverBullet, Silverlight

SilverBullet #10 System.Windows.Documents.Run

silverbullet I’d like to provide you with a SilverBullet™, a small snippet of Silverlight, a class or namespace hidden in the silverlight .NET framework, to help you out in times of need. It’s not to learn, but something to keep in your pocket. Just remember it’s there and you’re safe.

When showing text to a user it’s often necessary to show a few words in Italic or Bold. To do this, use the System.Windows.Documents.Run class. This class provides a small bit of HTML – like features inside a Silverlight TextBlock. But, instead of using HTML tags you have to use the Run class.

 

The Run class inherits from the abstract System.Windows.Documents.Inline which provides most of the properties to use.  A few of the most common are:

There are couple more properties which you can find here.

Another thing that might become useful when using the Run class to simulate a bit of HTML like behavior is the System.Windows.Documents.LineBreak class. This class does not have any properties or methods and can be compared to the <br /> tag in HTML.

 

Here’s a small example to show how the Run class  is used in xaml:

<Grid x:Name="LayoutRoot" Background="White"> 
    <TextBlock TextWrapping="Wrap" FontFamily="Verdana"> 
            This is an example with 
            <Run FontWeight="Black">Bold</Run>, 
            <Run FontStyle="Italic">Italic</Run> and 
            <Run Foreground="red">Colored</Run>                        
            text...<LineBreak /> 
            It's even possible to use<LineBreak />
            multiple <LineBreak />lines of text.
    </TextBlock> 
</Grid>

 

 

 

Shout it
Tags van Technorati:
dotNed blogger
kick it on DotNetKicks.com

Leave a Reply

Seo wordpress plugin by www.seowizard.org.
%d bloggers like this: