Adding UIElementContainer to RadRichTextBox

2 posts, 0 answers
  1. Joseph
    Joseph avatar
    135 posts
    Member since:
    Sep 2007

    Posted 14 Jan 2011 Link to this post

    Telerik.Windows.Documents.Model.InlineUIContainer cont = new Telerik.Windows.Documents.Model.InlineUIContainer();
    Telerik.Windows.Documents.Model.Span block = new Telerik.Windows.Documents.Model.Span();
     
    block.Text = "Hello World";
     
    cont.Children.Add(block);
    Telerik.Windows.Documents.Model.Section s = new Telerik.Windows.Documents.Model.Section();
    Telerik.Windows.Documents.Model.Paragraph p = new Telerik.Windows.Documents.Model.Paragraph();
     
    p.Children.Add(cont);
     
    s.Children.Add(p);
     
    rt.RadRichTextBox1.Document.Sections.Add(s);
     
    this.LayoutRoot.Children.Add(rt);



    I am getting the following error : 
    Unable to cast object of type 'Telerik.Windows.Documents.DocumentStructure.BoxNode' to type 'Telerik.Windows.Documents.DocumentStructure.BoxStartNode'.
  2. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 18 Jan 2011 Link to this post

    Hello Joseph,

     InlineUIContainers are used when you want to embed UIElements in RadRichTextBox. Spans are not UIElements and there is no reason to use InlineUIContainers to add a Span to the document. You can do that like this:

    Section section = new Section();
     
    Paragraph paragraph = new Paragraph();
    section.Blocks.Add(paragraph);
     
    Span span = new Span("Hello World");
    paragraph.Inlines.Add(span);
     
    this.RadRichTextBox1.Document.Sections.Add(section);

    If you have any other questions, do not hesitate to contact us again.


    Kind regards,
    Iva
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Back to Top