Saturday, October 6, 2012

RichTextBox in Silverlight

Team,

Here is a simple code to implement "RichTextBox" in silverlight.

Call this function WriteTextintoRichTextBox() and send in the message to be shown in the textbox.

Happy coding.

Cheers
Anand

The XAML file content:

<Border Background="Red" Width="300" Height="300" VerticalAlignment="Bottom" HorizontalAlignment="Left" CornerRadius="10">
<RichTextBox x:Name="richTextBox" Margin="5,5,5,5" IsReadOnly="True" >
</RichTextBox>
</Border>

The CS file content:

private void WriteTextintoRichTextBox(string toWriteInfo)
{
Paragraph rtbPara = new Paragraph();
Run rtbRun = new Run();
rtbRun.Text = toWriteInfo;
LineBreak rtbLineBreak = new LineBreak();
rtbPara.Inlines.Add(rtbRun);
this.richTextBox.Blocks.Add(rtbPara);
this.richTextBox.SelectAll();
}

All Blogs so far ...