views:

66

answers:

0

I have a flowdocument with a named Span" test1" which I want to replace the contents of programmatically

TextRange tr = new TextRange(this.test1.ContentStart,this.test1.ContentEnd);
Run run = this.test1.Inlines.First() as Run;

run.Text = "replaced text";

This works, however the problem is when doing the update the name of the span is removed (looking at the xaml source). Is this by design? Is there any way to retain the Id's? Hi, this is the method I use for debugging whats actually in the richtextbox (setting xaml source to textbox)

using (MemoryStream ms = new MemoryStream()) { tr = new TextRange(this.richTextBox1.Document.ContentStart, this.richTextBox1.Document.ContentEnd); tr.Save(ms, DataFormats.Xaml); ms.Position = 0;

            using (StreamReader sr = new StreamReader(ms))
            {
                this.textBox1.Text = sr.ReadToEnd();
            }
        }

This is the test contents of the richtextbox:

<FlowDocument>
        <Paragraph>
            This is my first  <Span Name="test1">a huge amount of space</Span> between it and the second paragraph?
        </Paragraph>
    </FlowDocument>