Latest News

  • Super Tower Defense Game
    Mar 10, 2010

    New to the games section is the new Super Tower Defense game. Defend your base from the ever advancing army of tanks, buggies...

  • New Rich Text Editor User Control
    Feb 19, 2010

    By popular request, here we present a re-usable User Control containing the Liquid RichTextBox along with the most common formatting functions included.

  • Silverlight 3 Controls V5.2.7 Released
    Feb 19, 2010

    This release includes several fixes for issues raised in the forum. The main improvement is to the RichTextBox which now provides access and methods to the document elements allowing...

  • Super Shoot Em Up Game
    Feb 04, 2010

    Added to the games section is the new Super Shoot 'Em Up game. Take control of a tank with your aim being to blow up your opposing tanks and collect all the powerups.

  • Silverlight 3 Controls V5.2.6 Released
    Feb 04, 2010

    This release includes some minor fixes for several forum posts. Please see the notes on the download page for full details on what has changed.

The RichTextArea Control

This new Silverlight 4 only control allows you to input RichText into your Silverlight application.  Here is a simple example of its use, complete with some simple formatting commands.

We have created an enhanced version of the RichTextArea control which enables you to Load and Save the content as basic HTML.  This control is available to download with all the source code here.



<UserControl x:Class="RichTextArea.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White" Width="300" Height="300">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Border Grid.Row="0" BorderThickness="1" BorderBrush="#8b919f">
            <StackPanel Orientation="Horizontal">
                <StackPanel.Background>
                    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                        <GradientStop Color="#ffffff" Offset="0.0" />
                        <GradientStop Color="#e3e8f4" Offset="0.5" />
                        <GradientStop Color="#cfd7eb" Offset="0.5" />
                        <GradientStop Color="#e9ecfa" Offset="1.0" />
                    </LinearGradientBrush>
                </StackPanel.Background>
                <StackPanel Orientation="Horizontal" Margin="4">
                    <ComboBox x:Name="selectFontFamily" Width="155" Height="23" Margin="0 0 2 0" SelectionChanged="SelectFontFamily_ItemSelected">
                        <ComboBoxItem Content="Arial" FontSize="14" FontFamily="Arial" IsSelected="True" />
                        <ComboBoxItem Content="Arial Black" FontSize="14" FontFamily="Arial Black" />
                        <ComboBoxItem Content="Comic Sans MS" FontSize="14" FontFamily="Comic Sans MS" />
                        <ComboBoxItem Content="Courier New" FontSize="14" FontFamily="Courier New" />
                        <ComboBoxItem Content="Lucida Sans Unicode" FontSize="14" FontFamily="Lucida Sans Unicode" />
                        <ComboBoxItem Content="Times New Roman" FontSize="14" FontFamily="Times New Roman" />
                        <ComboBoxItem Content="Trebuchet MS" FontSize="14" FontFamily="Trebuchet MS" />
                        <ComboBoxItem Content="Verdana" FontSize="14" FontFamily="Verdana" />
                    </ComboBox>
                    <ComboBox x:Name="selectFontSize" Width="45" Height="23" Margin="0, 0, 10, 0" SelectionChanged="SelectFontSize_ItemSelected">
                        <ComboBoxItem Content="6" />
                        <ComboBoxItem Content="7" />
                        <ComboBoxItem Content="8" />
                        <ComboBoxItem Content="9" />
                        <ComboBoxItem Content="10" />
                        <ComboBoxItem Content="11" />
                        <ComboBoxItem Content="12" IsSelected="True" />
                        <ComboBoxItem Content="13" />
                        <ComboBoxItem Content="14" />
                        <ComboBoxItem Content="15" />
                        <ComboBoxItem Content="16" />
                        <ComboBoxItem Content="17" />
                        <ComboBoxItem Content="18" />
                        <ComboBoxItem Content="20" />
                        <ComboBoxItem Content="22" />
                        <ComboBoxItem Content="24" />
                        <ComboBoxItem Content="26" />
                        <ComboBoxItem Content="28" />
                        <ComboBoxItem Content="36" />
                        <ComboBoxItem Content="48" />
                        <ComboBoxItem Content="72" />
                    </ComboBox>
                    <Button x:Name="makeBold" Width="24" Height="23" Margin="0 0 2 0" Click="MakeBold_Click">
                        <TextBlock x:Name="boldText" Text="B" FontFamily="Arial" FontSize="14" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" />
                    </Button>
                    <Button x:Name="makeItalic" Width="24" Height="23" Margin="0 0 2 0" Click="MakeItalic_Click">
                        <TextBlock x:Name="italicText" Text="I" FontFamily="Arial" FontSize="14" FontStyle="Italic" HorizontalAlignment="Center" VerticalAlignment="Center" />
                    </Button>
                    <Button x:Name="makeUnderline" Width="24" Height="23" Margin="0 0 10 0" Click="MakeUnderline_Click">
                        <TextBlock x:Name="underlineText" Text="U" FontFamily="Arial" FontSize="14" TextDecorations="Underline" HorizontalAlignment="Center" VerticalAlignment="Center" />
                    </Button>
                </StackPanel>
            </StackPanel>
        </Border>
        <RichTextArea x:Name="rta" Grid.Row="1" />
    </Grid>
</UserControl>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace RichTextArea
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void SelectFontFamily_ItemSelected(object sender, EventArgs e)
        {
            if (selectFontFamily != null)
            {
                rta.Selection.SetPropertyValue(TextElement.FontFamilyProperty, new FontFamily(((ComboBoxItem)selectFontFamily.SelectedItem).FontFamily.Source));
            }
        }

        private void SelectFontSize_ItemSelected(object sender, EventArgs e)
        {
            if (selectFontSize != null)
            {
                rta.Selection.SetPropertyValue(TextElement.FontSizeProperty, double.Parse(((ComboBoxItem)selectFontSize.SelectedItem).Content.ToString()));
            }
        }

        private void MakeBold_Click(object sender, RoutedEventArgs e)
        {
            rta.Selection.SetPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);
        }

        private void MakeItalic_Click(object sender, RoutedEventArgs e)
        {
            rta.Selection.SetPropertyValue(TextElement.FontStyleProperty, FontStyles.Italic);
        }

        private void MakeUnderline_Click(object sender, RoutedEventArgs e)
        {
            rta.Selection.SetPropertyValue(TextElement.TextDecorationsProperty, TextDecorations.Underline);
        }
    }
}


Here we show how to format text using the basic formatting commands such as Bold, Italic and Underline as well as Font Family and Size.

Post your Comments

No comments found.

Silverlight Controls

  • Rich TextBox

    Create and edit rich content with this slick and expandable Rich TextBox...

  • TreeView

    This easy to use TreeView comes with drag and drop, sorting, searching and much more...

  • Context Menu

    You too can have cool popup context menus in your Silverlight applications...

  • Resizable Dialog

    Draggable and resizable popup dialogs are what serious Silverlight developers need...

  • Spell Checker

    Real-time spell checking in Silverlight? We did it first here...