title | author | date | CreateTime | categories |
---|---|---|---|---|
WPF How to get plain text from RichTextBox |
lindexi |
2019-11-07 10:26:17 +0800 |
2019-11-07 10:26:16 +0800 |
WPF |
We can not find any function to get plain text from RichTextBox. But we can use TextRange to get plain text.
We create a RichTextBox in UI
<RichTextBox Name="RichTextBox">
<FlowDocument>
<Paragraph>
<Run>Paragraph 1</Run>
</Paragraph>
<Paragraph>
<Run>Paragraph 2</Run>
</Paragraph>
<Paragraph>
<Run>Paragraph 3</Run>
</Paragraph>
</FlowDocument>
</RichTextBox>
And we can use TextRange to get plain text from RichTextBox
string text = new TextRange(RichTextBox.Document.ContentStart, RichTextBox.Document.ContentEnd).Text