views:

602

answers:

1

What's required to create a style for a RichTextBox that includes visuals for the scrollbars and a background color for the space behind the text?

+2  A: 

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:

  1. Draw a RichTextBox onto your window using the RichTextBox tool
  2. From the menu select Edit Style > Edit a Copy
  3. Choose a name for the RichTextBox style and select which dictionary to store it in
  4. 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
  5. In the Resources tab delete the TextBoxBase style and TextBoxBorder brush
  6. Double-click your RichTextBoxStyle in the Resources tab to open it again
  7. Right-click the RichTextBox and select Edit Control Parts (Template) > Edit Template
  8. Right-click the PART_ContentHost ScrollViewer and select Edit Control Parts (Template) > Edit a Copy
  9. 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" ...
Ray Burns