Inserting apostrophe programmatically

2 posts, 0 answers
  1. Cameron Molyneux
    Cameron Molyneux avatar
    79 posts
    Member since:
    Jan 2010

    Posted 17 Dec 2012 Link to this post

    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

  2. Vasil
    Admin
    Vasil avatar
    124 posts

    Posted 20 Dec 2012 Link to this post

    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.

  3. DevCraft banner
Back to Top