WPF - RichTextBox 上的滚动条和背景的样式
为 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
向 RichTextBox 的滚动条添加视觉效果
(或以其他方式修改这些滚动条的外观)
假设您要求为 RichTextBox 的滚动条创建自定义视觉样式(例如,向其添加新图标),您只需在 Expression Blend 中单击几下即可完成此操作:
Edit Style >编辑副本
替换新样式的内容;
TextBoxBase 样式的部分,然后返回到设计视图编辑控制部件(模板)>编辑模板
PART_ContentHost
ScrollViewer
并选择编辑控件部件(模板)>编辑副本
ScrollViewer
模板选择名称此时,您可以通过执行以下两项操作之一将您喜欢的任何视觉元素添加到水平和垂直滚动条: 1. 右键单击滚动条并选择
Group Into >网格 (Ctrl-G)
,然后向其中添加视觉效果,或者 2. 右键单击滚动条并选择编辑控件部件(模板)>再次编辑副本以装饰滚动条的各个部分,例如拇指或箭头。
上面解释了如何添加创建将自定义视觉效果添加到 RichTextBox 滚动条的样式。当然,除非需要滚动,否则滚动条实际上不会出现,或者通过以下方式强制滚动条可见:
设置文本后面空间的背景颜色
这本身就是简单。只需设置背景属性:
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:
RichTextBox
onto your window using the RichTextBox toolEdit Style > Edit a Copy
<Setter Property="Template">
sction of the TextBoxBase style, then return to Design ViewEdit Control Parts (Template) > Edit Template
PART_ContentHost
ScrollViewer
and selectEdit Control Parts (Template) > Edit a Copy
ScrollViewer
templateAt 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 choosingEdit 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:
Setting the background color for the space behind the text
This is simplicity itself. Just set the Background property: