我可以为 WPF 文本框中文本的不同部分着色吗?
我有一个 WPF 文本框,用户可以在其中输入 XHTML。
XAML...
<TextBox Name="TextBoxContentBody"
TextWrapping="Wrap"
AcceptsReturn="True"
VerticalScrollBarVisibility="Visible"
FontFamily="Consolas"
... />
它看起来像这样:
我宁愿它看起来像这样(经过 Photoshop 处理的模拟- up):
我该如何完成此操作?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要使用 RichTextBox那。
You'll want to use a RichTextBox for that.
就像肯特说的,对于文本框,你只能使用一种颜色。
这是一篇关于简单 RTB 语法突出显示的小文章,应该可以满足您的大部分需求。
http://blogs.microsoft .co.il/blogs/tamir/archive/2006/12/14/RichTextBox-syntax-highlighting.aspx
Like Kent said with a TextBox you're stuck with one color.
Here is a small article on simple RTB syntax highlighting that should give you most of what you need.
http://blogs.microsoft.co.il/blogs/tamir/archive/2006/12/14/RichTextBox-syntax-highlighting.aspx
您必须创建继承 TextBox 控件的自定义控件并遵循以下示例:
绘制格式化文本
You will have to create a custom control inheriting the TextBox control and follow this example:
Drawing Formatted Text