Customizing the Rich TextBox With Styles

The Rich TextBox control can be skinned using the standard Silverlight 2 method of setting Styles in the App.xaml file of your Silverlight project.

Example of how to Apply a Skin to the Rich TextBox

These styles are placed in your XAML and referred to using the Style property:


    <Style TargetType="local:RichTextBox">
        <Setter Property="Background" Value="#ffffff" />
        <Setter Property="BorderBrush" Value="#a4a4a4" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="Padding" Value="2" />
        <Setter Property="VerticalScrollBarVisibility" Value="Auto" />
        <Setter Property="HorizontalScrollBarVisibility" Value="Auto" />
        <Setter Property="PopupTitle" Value="Spelling Suggestions:" />
        <Setter Property="PopupAddText" Value=" Add " />
        <Setter Property="PopupReplaceText" Value=" Replace " />
        <Setter Property="SelectionBackground" Value="#506484f6" />
        <Setter Property="SelectMode" Value="Edit" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:RichTextBox">
                    <ScrollViewer x:Name="ElementContainer" Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}" VerticalScrollBarVisibility="{TemplateBinding VerticalScrollBarVisibility}" HorizontalScrollBarVisibility="{TemplateBinding HorizontalScrollBarVisibility}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" IsTabStop="False">
                        <Border x:Name="ElementGrid" VerticalAlignment="Top">
                            <local:RichTextPanel x:Name="ElementChildren" HorizontalAlignment="Left" VerticalAlignment="Top" Background="{TemplateBinding Background}">
                                <local:RichTextPanel.Resources>
                                    <Storyboard x:Name="ElementCursorBlink" BeginTime="0" RepeatBehavior="forever">
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="ElementCursor" Storyboard.TargetProperty="(UIElement.Opacity)" Duration="00:00:01">
                                            <LinearDoubleKeyFrame Value="1" KeyTime="0:0:0" />
                                            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0.5" />
                                            <LinearDoubleKeyFrame Value="1" KeyTime="0:0:1" />
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </local:RichTextPanel.Resources>
                                <local:RichTextPanel.RenderTransform>
                                    <ScaleTransform x:Name="ElementScale" ScaleX="1" ScaleY="1" />
                                </local:RichTextPanel.RenderTransform>
                                <local:RichTextPanel.Children>
                                    <Rectangle x:Name="ContentElementBackGround" IsHitTestVisible="False" Fill="White" Opacity="0" />
                                    <ContentControl x:Name="ContentElement" IsTabStop="False" Width="0" Height="0" Opacity="0" />
                                    <Canvas x:Name="ElementObjectSelection" />
                                    <Rectangle x:Name="ElementCursor" Width="1" IsHitTestVisible="False" Fill="#000000" Visibility="Collapsed" />
                                    <Polygon x:Name="ElementSelection" IsHitTestVisible="False" Fill="{TemplateBinding SelectionBackground}" />
                                    <Popup x:Name="ElementBubblePopup">
                                        <Canvas x:Name="ElementBubble" Width="168" Height="108" Cursor="Arrow">
                                            <Canvas.RenderTransform>
                                                <ScaleTransform x:Name="ElementBubbleScale" ScaleX="1" ScaleY="1" />
                                            </Canvas.RenderTransform>
                                            <Polygon x:Name="ElementBubbleBackground" Stroke="#888888" StrokeThickness="1">
                                                <Polygon.Fill>
                                                    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                                                        <GradientStop Color="#ffffff" Offset="0.0" />
                                                        <GradientStop Color="#eeeeee" Offset="1.0" />
                                                    </LinearGradientBrush>
                                                </Polygon.Fill>
                                            </Polygon>
                                            <TextBlock Text="{TemplateBinding PopupTitle}" FontFamily="Arial" FontSize="14" FontWeight="Normal" Canvas.Left="8" Canvas.Top="8" />
                                            <ComboBox x:Name="ElementSuggestions" Canvas.Left="8" Canvas.Top="30" FontFamily="Arial" FontSize="14" FontWeight="Normal" Width="150" />
                                            <Grid Canvas.Left="8" Canvas.Top="65" Width="150">
                                                <Button x:Name="ElementAdd" FontFamily="Arial" FontSize="14" FontWeight="Normal" Content="{TemplateBinding PopupAddText}" IsTabStop="False" HorizontalAlignment="Left" />
                                                <Button x:Name="ElementReplace" FontFamily="Arial" FontSize="14" FontWeight="Normal" Content="{TemplateBinding PopupReplaceText}" IsTabStop="False" Margin="2 0 0 0" HorizontalAlignment="Right" />
                                            </Grid>
                                        </Canvas>
                                    </Popup>
                                    <ContentControl x:Name="ElementContext" IsTabStop="False" Content="{TemplateBinding ContextMenu}" Cursor="Arrow">
                                        <ContentControl.RenderTransform>
                                            <ScaleTransform x:Name="ElementContextScale" ScaleX="1" ScaleY="1" />
                                        </ContentControl.RenderTransform>
                                    </ContentControl>
                                </local:RichTextPanel.Children>
                            </local:RichTextPanel>
                        </Border>
                    </ScrollViewer>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


As you can see, styling is a powerful method of customizing the controls to suite the look and feel of your Silverlight application.

 
 
Latest Games
Zombie Escape
Apr 19, 2016
Plays: 2,513

Zombie Escape ScreenshotDrive fast before the crazy mutant zombies get you!

6 Ratings/4.1 Average
Car Parking
Jan 16, 2016
Plays: 2,380

Car Parking ScreenshotGuide the car to its parking space in this fun Car Parking game.

1 Rating/5 Average
Trash It
Jan 11, 2016
Plays: 2,284

Trash It ScreenshotAim for the Trash Can and get the various items of Trash in the bin.

4 Ratings/5 Average
Sky Fly
Jan 11, 2016
Plays: 2,435

Sky Fly ScreenshotFly your plane in this colorful vertical scrolling shoot-em-up. Blast the bad guys and collect any bonus's they leave behind.

1 Rating/5 Average
Professor Snappy
Jan 11, 2016
Plays: 1,969

Professor Snappy ScreenshotPop as many bubbles as possible in this fun and colorful bubble popping game. The levels start off easy enough but gradually get harder!

1 Rating/5 Average
Monster Match Saga
Jan 10, 2016
Plays: 2,294

Monster Match Saga ScreenshotHere we have a bunch of monsters that need to be matched up. Look out for the bomb and spinning monsters that will cause special damage!

3 Ratings/4.6 Average
Fly Bird Fly
Jan 10, 2016
Plays: 2,121

Fly Bird Fly ScreenshotGuide your friendly Bird through the maze of pipes and other obstacles collecting the Stars in this cool arcade game inspired by the legendary Flappy Bird.

1 Rating/5 Average
Life In One
Jan 10, 2016
Plays: 2,296

Life In One ScreenshotYou are stranded on an Alien planet. Your goal is to build a space rocket and escape. Start by building units to create power and mine the metal patches. Build defenses to defend your base from the advancing Aliens and Zombies!

2 Ratings/3 Average
X Pool
Jan 02, 2016
Plays: 2,912

X Pool ScreenshotPlay Pool against the computer or battle against your friends in the online mode!

3 Ratings/3 Average
Fruit Slicer
Jan 02, 2016
Plays: 2,009

Fruit Slicer ScreenshotSlice the fruit that is thrown up onto the screen. Slice the fruit into multiple pieces for maximum points!

1 Rating/5 Average