Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 211
Zack Peterson Avatar asked Feb 24 '09 21:02

Zack Peterson


People also ask

How do I highlight a TextBox in WPF?

You can use the following code to achieve your purpose: textBoxToHighlight. Focus(); textBoxToHighlight. Select(0, textBoxToHighlight.

What is TextBox in WPF?

The TextBox class enables you to display or edit unformatted text. A common use of a TextBox is editing unformatted text in a form. For example, a form asking for the user's name, phone number, etc would use TextBox controls for text input.


1 Answers

You'll want to use a RichTextBox for that.

like image 156
Kent Boogaart Avatar answered Sep 17 '22 18:09

Kent Boogaart