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

Import Microsoft InlineUIContainer to RichTextBox

7 Answers 84 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Joseph
Top achievements
Rank 1
Joseph asked on 31 Jan 2011, 11:31 AM
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

7 Answers, 1 is accepted

Sort by
0
Joseph
Top achievements
Rank 1
answered on 31 Jan 2011, 01:00 PM
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.





0
Joseph
Top achievements
Rank 1
answered on 31 Jan 2011, 04:04 PM
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.
0
Iva Toteva
Telerik team
answered on 31 Jan 2011, 06:33 PM
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>>
0
Joseph
Top achievements
Rank 1
answered on 01 Feb 2011, 09:59 AM
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);
              
             
 
        }
0
Joseph
Top achievements
Rank 1
answered on 02 Feb 2011, 09:17 AM
I used this :

this._paragraph.Inlines.Add(inline);


Instead of : this.InsertInline(inline);

0
Iva Toteva
Telerik team
answered on 03 Feb 2011, 08:33 AM
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>>
0
Roman
Top achievements
Rank 1
answered on 20 Aug 2012, 08:54 AM
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?
Tags
RichTextBox
Asked by
Joseph
Top achievements
Rank 1
Answers by
Joseph
Top achievements
Rank 1
Iva Toteva
Telerik team
Roman
Top achievements
Rank 1
Share this question
or