1

私は WPF の RichTextBox を初めて使用します。特定の色で行上のテキストを強調表示する方法を知りたいです。

背景が黄色のリッチ テキスト ボックスがあり、それにフロー ドキュメントを割り当てたとします。

richTextBox.Background = Brushes.LightYellow;
var mcFlowDoc = new FlowDocument();
var para = new Paragraph();
para.Inlines.Add(new Run("This is the first line.\n"));
para.Inlines.Add(new Run("This is the second line.\n"));
para.Inlines.Add(new Run("This is the third line."));
mcFlowDoc.Blocks.Add(para);
richTextBox.Document = mcFlowDoc;

3 行目のハイライト色を赤に変更するには、次に何をする必要がありますか? 選択の強調表示の色について話しているのではなく、通常のテキストの強調表示 (ワードパッドなど)

解決策があれば、C# コードで解決したいのですが、XAML 編集から離れたいと思っています。

4

1 に答える 1

2
    Run run = new Run("Red is the third line.\n");
    // run.Foreground = Brushes.Red;
    run.Background = Brushes.Red;
    para.Inlines.Add(run);
于 2012-09-15T12:46:18.750 に答える