【发布时间】:2016-01-24 18:18:23
【问题描述】:
我使用 C# WPF 并且我有richtextbox,我想将一些文本着色为红色、一些绿色和一些黑色。 该怎么做?
【问题讨论】:
-
请考虑这个问题。它可以帮助你stackoverflow.com/questions/17971300/…
标签: wpf
我使用 C# WPF 并且我有richtextbox,我想将一些文本着色为红色、一些绿色和一些黑色。 该怎么做?
【问题讨论】:
标签: wpf
在您的 RichTextBox 中使用 FlowDocumentReader。因此,您可以使用文档类:List、Paragraph、Section、Table、LineBreak、Figure、Floater 和 Span,并更改它们的属性:
<FlowDocumentReader x:Name="myDocumentReader" Height="269.4">
<FlowDocument>
<Section Foreground = "Yellow" Background = "Black">
<Paragraph FontSize = "20">
Here are some fun facts about the WPF Documents API!
</Paragraph>
</Section>
<List x:Name="listOfFunFacts"/>
<Paragraph x:Name="paraBodyText"/>
</FlowDocument>
</FlowDocumentReader>
您还可以在代码中填充和更改属性,例如,List right:
this.listOfFunFacts.Foreground = Brushes.Brown;
this.listOfFunFacts.FontSize = 14;
this.listOfFunFacts.MarkerStyle = TextMarkerStyle.Circle;
this.listOfFunFacts.ListItems.Add(new ListItem( new Paragraph(new Run("Sample Text"))));
【讨论】: