spi*_*man 1 c# wpf richtextbox
我在MSDN中使用这个简单的例子来插入一行RichTextBox.
FlowDocument myFlowDoc = new FlowDocument();
Run myRun = new Run("This is flow content and you can ");
Bold myBold = new Bold(new Run("edit me!"));
Paragraph myParagraph = new Paragraph();
myParagraph.Inlines.Add(myRun);
myParagraph.Inlines.Add(myBold);
myFlowDoc.Blocks.Add(myParagraph);
RichTextBox myRichTextBox = new RichTextBox();
myRichTextBox.Document = myFlowDoc;
Run Code Online (Sandbox Code Playgroud)
我想在文本行中应用一种选择的颜色,但是怎么做呢?
本Paragraph或Run类没有任何直接的方法来改变颜色.
编辑
我不想使用所有的awkard SelectionStart,SelectionEnd链接帖子上张贴的东西!
我的情况不同而且更简单:mm8发布的解决方案解释了它并且非常优雅.一行代码就是这样!
请看答案!
本
Paragraph或Run类没有任何直接的方法来改变颜色.
在Run类继承自TextElement这个类有一个Foreground可以设置一个属性Brush:
Run myRun = new Run("This is flow content and you can ") { Foreground = Brushes.Red };
Bold myBold = new Bold(new Run("edit me!") { Foreground = Brushes.Gray });
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
79 次 |
| 最近记录: |