我可以为 WPF 文本框中文本的不同部分着色吗?

发布于 2024-07-13 23:15:40 字数 492 浏览 5 评论 0 原文

我有一个 WPF 文本框,用户可以在其中输入 XHTML。

XAML...

<TextBox Name="TextBoxContentBody"
         TextWrapping="Wrap"
         AcceptsReturn="True"
         VerticalScrollBarVisibility="Visible"
         FontFamily="Consolas"
         ... />

它看起来像这样:

在此处输入图像描述

我宁愿它看起来像这样(经过 Photoshop 处理的模拟- up):

在此处输入图像描述

我该如何完成此操作?

I've got a WPF TextBox into which my users type XHTML.

XAML...

<TextBox Name="TextBoxContentBody"
         TextWrapping="Wrap"
         AcceptsReturn="True"
         VerticalScrollBarVisibility="Visible"
         FontFamily="Consolas"
         ... />

It looks like this:

enter image description here

I'd rather that it looked like this (Photoshopped mock-up):

enter image description here

How might I accomplish this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小兔几 2024-07-20 23:15:40

您需要使用 RichTextBox那。

You'll want to use a RichTextBox for that.

书信已泛黄 2024-07-20 23:15:40

就像肯特说的,对于文本框,你只能使用一种颜色。

这是一篇关于简单 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

奢望 2024-07-20 23:15:40

您必须创建继承 TextBox 控件的自定义控件并遵循以下示例:

绘制格式化文本

You will have to create a custom control inheriting the TextBox control and follow this example:

Drawing Formatted Text

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文