This is a migrated thread and some comments may be shown as answers.

Inserting apostrophe programmatically

1 Answer 86 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Cameron Molyneux
Top achievements
Rank 1
Cameron Molyneux asked on 17 Dec 2012, 01:31 PM
Hi,

I am trying to insert a simple Span with an apostrophe in it, however it is not working.

After adding an apostrophe normally in the text editor I get this:

    <t:Paragraph>
      <t:Span Text="It&#39;s a test" />
    </t:Paragraph>
And that of course displays an apostrophe as expected.

When I try to add it at run time, I replace any apostrophes with &#39;. I have also tried using &apos;.

I end up with this:
<t:Span FontFamily="Arial" FontSize="13.3366670608521" FontStyle="Italic" FontWeight="Bold" Text="It&#39;s a test" UnderlineDecoration="Line"/>

And now in the document I see "It&#39;s a test".

How do I get an apostrophe in there?

Regards

1 Answer, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 20 Dec 2012, 02:00 PM
Hi Cameron,

Thank you for your question.

To insert programmatically content in your document you could use the Insert(string) and InsertFragment(DocumentFragment) methods. Please refer to the following code snippets below which demonstrate sample functiona for your purpose:

private void Button_Click(object sender, RoutedEventArgs e)
{
    this.radRichTextBox.Insert("'");
}

private void Button_Click(object sender, RoutedEventArgs e)
{
    RadDocument document = new RadDocument();
    Section section = new Section();
    Paragraph paragraph = new Paragraph();
    Span span = new Span("It's a test.");
    paragraph.Inlines.Add(span);
    section.Blocks.Add(paragraph);
    document.Sections.Add(section);
 
    DocumentFragment documentFragment = new DocumentFragment(document);
    this.radRichTextBox.Document.InsertFragment(documentFragment);
}

Note that when setting the text of a Span or inserting text, the apostrophe must not be escaped as in the inner representation of the spans, the text need not be escaped. At the same time, the providers and XamlFormatProvider will make sure to escape all characters in the respective format when you save the document.
 
I hope this helps. Please, do not hesitate if you need further assistance.

Greetings,
Vasil
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
RichTextBox
Asked by
Cameron Molyneux
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Share this question
or