Can someone highlight this for me, I have a RichTextBox that loads the xaml file into it. I need to replace some parts of the RichTxtBox text with real data, that is, "[our_name]" is replaced by "Billie Brags". My xaml file contains formatting like bold and font size.
When I run my code (shown below), I can change the text OK, but I will lose the formatting.
Any idea how I can do this and save the formatting?
thanks
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); using (fs) { TextRange RTBText = new TextRange(rtb_wording.Document.ContentStart, rtb_wording.Document.ContentEnd); RTBText.Load(fs, DataFormats.Xaml); } TextRange tr = new TextRange(rtb_wording.Document.ContentStart, rtb_wording.Document.ContentEnd); string rtbContent = tr.Text; rtbContent = rtbContent.Replace("<our_name>", "Billie Brags"); System.Windows.MessageBox.Show(rtbContent); FlowDocument myFlowDoc = new FlowDocument();
source share