要以编程方式填充的彩色文本块

Ent*_*ity 3 wpf textarea

我希望功能相当于支持多种颜色的文本块.

我已经尝试创建一个UserControl并添加多个文本块并将其前景设置为我需要的颜色,但是这非常慢,因为我将每隔几秒更改和清除文本.

我也尝试使用RichTextBox,但似乎它不是设计为以编程方式填充.

建议?

max*_*max 7

TextBlock可以显示多个"运行" - 具有相同格式的文本块.使用Inlines属性访问它们:

using System.Windows.Documents;
using System.Windows.Media;

var inlines = textBlock.Inlines;
inlines.Add(new Run("This is red") { Foreground = Brushes.Red });
inlines.Add(new LineBreak()); // in case if you want new line
inlines.Add(new Run("And this is blue") { Foreground = Brushes.Blue });
Run Code Online (Sandbox Code Playgroud)