WPF - 在Richtextbox中为一些文本加下划线

时间:2014-08-21 09:50:44

标签: c# wpf richtextbox underline text-formatting

我有一个WPF RichTextBox(rtbControl),内容如下:

  

这不是带下划线的线   这是带下划线的

我想强调第二行,我该怎么做?

2 个答案:

答案 0 :(得分:2)

由于RTB的内容是FlowDocument,因此您必须创建适当的文档结构:

    <RichTextBox>
        <FlowDocument>
            <Paragraph>
                <Run Text="This is not an underline line"/>
            </Paragraph>
            <Paragraph>
                <Underline>
                    <Run Text="This is an underline line"/>
                </Underline>
            </Paragraph>
        </FlowDocument>
    </RichTextBox>

答案 1 :(得分:-1)

<RichTextBox>
    <FlowDocument>
        <Paragraph>
            This is not an underline line
        </Paragraph>     

        <Paragraph>
            <Underline>This is an underline line</Underline>
        </Paragraph>     

    </FlowDocument>       

</RichTextBox>