Can I color different parts of text in a WPF TextBox?

Zack Peterson picture Zack Peterson · Feb 24, 2009 · Viewed 26.4k times · Source

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?

Answer

Kent Boogaart picture Kent Boogaart · Feb 24, 2009

You'll want to use a RichTextBox for that.