Adding visuals to a RichTextBox s scroll bars
(or otherwise modifying the look of those scrollbars)
Assuming you are asking to create custom visual style for RichTextBox s scrollbars (for example, to add new icons to them), you can do this with just a few clicks in Expression Blend:
- Draw a
RichTextBox
onto your window using the RichTextBox tool
- From the menu select
Edit Style > Edit a Copy
- Choose a name for the RichTextBox style and select which dictionary to store it in
- Hit F11 to see the XAML, replace the contents of your new style with the
<Setter Property="Template">
sction of the TextBoxBase style, then return to Design View
- In the Resources tab delete the TextBoxBase style and TextBoxBorder brush
- Double-click your RichTextBoxStyle in the Resources tab to open it again
- Right-click the RichTextBox and select
Edit Control Parts (Template) > Edit Template
- Right-click the
PART_ContentHost
ScrollViewer
and select Edit Control Parts (Template) > Edit a Copy
- Choose a name for new
ScrollViewer
template
At this point you can aad whatever visual elements you like to the horizontal and vertical scrollbars by doing one of two things: 1. Right-clicking a scrollbar and choosing Group Into > Grid (Ctrl-G)
, then adding Visuals to it, or 2. Right-clicking a scrollbar and choosing Edit Control Parts (Template) > Edit a Copy
again to decorate individual parts of the scrollbar such as the thumbs or the arrows.
The above explains how to add create a style that adds custom visuals to the scrollbars of a RichTextBox. Of course the scrollbars won t actually appear unless scrolling is necessary or they are forced to be visible with eg:
<RichTextBox ScrollViwer.VerticalScrollBarVisibilty="Visible" ...
Setting the background color for the space behind the text
This is simplicity itself. Just set the Background property:
<RichTextBox Background="Purple" ...