在流程文档中更改内联 [英] Changing inline in flowdocument
本文介绍了在流程文档中更改内联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的流程文件:
I have a flowdocument like this:
var mcFlowDoc = new FlowDocument();
var para = new Paragraph();
para.Inlines.Add(new Run("This is the first line."));
para.Inlines.Add(new Run("This is the second line."));
para.Inlines.Add(new Run("This is the third line."));
mcFlowDoc.Blocks.Add(para);
richTextBox.Document = mcFlowDoc;
我需要通过单击该文本的任何部分来更改其中一行的背景.
I need to change the background of one of the lines by clicking on any part of that text.
首先,我试图更改给定内联的背景(无论鼠标点击),但我无法做到.
First of all I am trying to change the background of a given inline (regardless of mouse click), but I am unable to do it.
任何帮助将不胜感激.
我可以更改运行的背景颜色,但随后我必须再次添加所有运行并重绘.我需要它更快地工作,所以我只是想改变一个运行而不重新添加所有.
I could change the background color of a run, but then I had to add all runs again and redraw. I need it to work faster, so I'm just trying to change a run without adding all again.
推荐答案
您可以为 Run
添加一个 Style
以订阅例如MouseLeftButtonDown
You could add a Style
for Run
to subscribe e.g. MouseLeftButtonDown
<RichTextBox.Resources>
<Style TargetType="Run">
<EventSetter Event="MouseLeftButtonDown" Handler="Run_Click" />
</Style>
</RichTextBox.Resources>
并像这样处理事件
void Run_Click(object sender, MouseButtonEventArgs e)
{
Run run = sender as Run;
run.Background = Brushes.Red;
}
这篇关于在流程文档中更改内联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文