English 中文(简体)
WPF - Style for the scrollbars and background on a RichTextBox
原标题:

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?

最佳回答

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" ...
问题回答

暂无回答




相关问题
Creating a Style in code behind

Does anyone know how to create a wpf Style in code behind, I can t find anything on the web or MSDN docs. I have tried this but it is not working: Style s = new Style(typeof(TextBlock)); s....

WPF Custom Themes

I have a simple question which is giving me some difficulty. I have downloaded a custom them for WPF of the net. Now i want to apply this theme to my App instead of the default one. How do i do that,...

Is it sometimes bad to use <BR />?

Is it sometimes bad to use <BR/> tags? I ask because some of the first advice my development team gave me was this: Don t use <BR/> ; instead, use styles. But why? Are there negative ...

WPF - How to apply effect to a cropped image?

I have an Image being clipped like so: <Image Width="45" Grid.Column="0" Source="{Binding Photo}"> <Image.Clip> <RectangleGeometry Rect="0,0,45,55" RadiusX="8" RadiusY="8" /...

WPF ListView : Header styling

I want to have a ListView with columns and a particular style: The background for ALL column headers should be transparent except when the mouse is over in one of them. When this happends, the ...

热门标签