2

I am upgrading an old program from windows forms to wpf. On the old windows forms app I had a RTB and I could paste text to it from a web page or visual studios and it would keep the text size color and font.

I now have a wpf rich text box but when I paste (ctrl v) text I have copied from a web page it is just the plane black text. How can I get it to behave like the old win forms one and paste the formatted text?

    <RichTextBox Grid.Row="1" Margin="7" Name="RichTextBox1" Background="#FFEDEAEA">
    </RichTextBox>

The idea is to be able to paste formatted text then save it and reload it later, and I have a felling saving and loading the formatted text will be the next issue.

scott lafoy
  • 1,001
  • 1
  • 13
  • 30

1 Answers1

0

1., There is no Text property, but there is a Document one. You can receive the data from it in the codebehind by calling:

string text = new TextRange(RichTextBox1.Document.ContentStart, RichTextBox1.Document.ContentEnd).Text;

2., There is an Extended WPF Toolkit, which adds the Text dependency property to the RTB.

aniski
  • 1,263
  • 1
  • 16
  • 31