Import Microsoft InlineUIContainer to RichTextBox

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

    Posted 31 Jan 2011 Link to this post

    Hi guys,

    I have a class that renders a System.Windows.Documents.InlineUIContainer that I want to import it the Telerik RichTextBox.

    the old InlineUIContainer consist of a Border, inside it there is a textblock.

    I want to import the same structure to Telerik RichTextBox, but the telerik control only accepts elements from Telerik.Windows.Documents.Model which contain an InlineUIContainer  that doesn't accept a Border element.

    I am using the following code to feed the telerik control :

    paragraph.Children.Add(inline);
     
    section.Children.Add(paragraph);
                      
    box.Document.Sections.Add(section);

    Any suggestions ?

    Thanks
  2. Joseph
    Joseph avatar
    135 posts
    Member since:
    Sep 2007

    Posted 31 Jan 2011 Link to this post

    I need to insert an InlineUIContainer that I can put inside some text. In Telerik RichTextBox control it is impossible.

    The reason behind this is that I want to seperate Span elements from InlineUIContainer elements.

    If we take this string: <a> Text </a>

    I represent the tags <a> and </a> as InlineUIContainers and the text 'and' as a span this way I seperate the 2 type of text.

    Thanks.





  3. DevCraft banner
  4. Joseph
    Joseph avatar
    135 posts
    Member since:
    Sep 2007

    Posted 31 Jan 2011 Link to this post

    I found a way to insert an InlineUiContainer using this code :

    TextBlock block = new TextBlock();
              block.Text = "Joseph";
     
     
              Telerik.Windows.Documents.Model.InlineUIContainer container = new Telerik.Windows.Documents.Model.InlineUIContainer(block, new Size());
     
              //box.Focus();
     
              box.InsertInline(container);

    the problem with this approach is I need to set the size ( height and width) of the text. Is there a way to make it auto ? so the InlineUIContainer shows aligned Vertically with other text in the RichTextBox ?

    Thanks.
  5. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 31 Jan 2011 Link to this post

    Hello Joseph,

    InlineUIContainers' Size cannot be set to auto, but you can adopt the following approach:

    private void buttonInsertTextBlock_Click(object sender, RoutedEventArgs e)
    {
        TextBlock textblock = new TextBlock();
        textblock.FontFamily = new FontFamily("Verdana"); //You may need to adjust the FontFamily and FontSize properties
        textblock.FontSize = Unit.PointToDip(12);
        textblock.Text = "new TextBlock";   
        InlineUIContainer container = new InlineUIContainer(textblock, new Size(textblock.ActualWidth, textblock.ActualHeight-3));
        this.radRichTextBox.InsertInline(container);
    }
    Subtracting 3 from the ActualHeight is needed to properly align the TextBlock with the regular RadRichTextBox text. Please note that you should adjust this according to your specific font size.
    If you have other questions, do not hesitate to contact us again.

    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>>
  6. Joseph
    Joseph avatar
    135 posts
    Member since:
    Sep 2007

    Posted 01 Feb 2011 Link to this post

    Thanks a bunch.

    I appreciate your help guys.

    Any idea when the SP1 will be released ? 

    There is a bug where when you resize the RichTextBox, some of the text gets overlapped or hidden. Telerik team promised to fix that in the next service pack.

    Thanks again.

    Edit : When I moved the code to the user control Load event, the usercontrol threw this exception :

    The type initializer for 'Telerik.Windows.Documents.Layout.RadTextMeasurer' threw an exception.

    Here is the code :

    void MainPage_Loaded(object sender, RoutedEventArgs e)
           {
            
                  box.AddText(span);
     
                  TextBlock block = new TextBlock();
     
     
                  System.Windows.Controls.Border b = new System.Windows.Controls.Border();
                  b.Background = new SolidColorBrush(Colors.Gray);
                  b.BorderThickness = new Thickness(0, 0, 0, 0);
                  b.Child = block;
                  //block.FontSize = Unit.PointToDip(12);
                  block.Text = "Joseph";
                  b.Height = 100;
                  b.Margin = new Thickness(0, 4, 0, 0);
                  Telerik.Windows.Documents.Model.InlineUIContainer container = new Telerik.Windows.Documents.Model.InlineUIContainer(b, new Size(block.ActualWidth, block.ActualHeight));
     
                  //box.Focus();
     
                  box.InsertInline(container);
     
                  this.panel.Children.Add(box);
                  
                 
     
            }
  7. Joseph
    Joseph avatar
    135 posts
    Member since:
    Sep 2007

    Posted 02 Feb 2011 Link to this post

    I used this :

    this._paragraph.Inlines.Add(inline);


    Instead of : this.InsertInline(inline);

  8. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 03 Feb 2011 Link to this post

    Hello Joseph,

    I am glad to hear that you were able to resolve the issue yourself. Please note that directly adding elements to the document tree like this will clear the change history so far (i.e. Ctrl+Z) whether this is desirable or not.
    If you meet any other difficulties, do not hesitate to contact us again.

    Best wishes,
    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>>
  9. Roman
    Roman avatar
    1 posts
    Member since:
    Aug 2012

    Posted 20 Aug 2012 Link to this post

    Hello, Iva.
    Please tell me if I want instead of a TextBlock use the TextBox field, the actual dimensions are equal to zero and there is an exception. What to do in such a situation?
Back to Top
DevCraft banner