WPF RadRichTextDocument and InlineUiElement size

1 Answer 29 Views
Buttons
Valentin
Top achievements
Rank 1
Valentin asked on 26 Feb 2024, 09:01 PM

Hello. 
I want to add Custom User control to RadDocument in RadRichTextBox. So I use InlineUiContainer to do that. And add it to paragraph.

And it looks so that I have to define height and width to make it so that it will take correct space in the document layout. If I skip this step then it looks like it takes zero width and height.
Looks strange. Because of course I don't know physical size of element in advance. As workaround I can do some "magic" with Loaded event and extract size of UiElement once it was rendered. And it works. But definitely it looks like a dirty code. 
I believe I miss something. Please help me. What am I doing wrong here? :)

By the way when I need to add InlineUiElement  to standard WPF RichTextBox it does all calculations of size by itself.

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 28 Feb 2024, 06:54 AM

Hi Valentin,

Yes, this is a requirement in our framework. You can measure the item before adding it and set the size. Here is an example: 

Section section = new Section();
Paragraph paragraph = new Paragraph();
InlineUIContainer container = new InlineUIContainer();

var element = new Button() { Content = "Test" };
container.UiElement = element;

element.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));  

container.Height = element.DesiredSize.Height;
container.Width = element.DesiredSize.Width;


paragraph.Inlines.Add(new Span("Test"));
paragraph.Inlines.Add(container);
paragraph.Inlines.Add(new Span("Test"));
section.Blocks.Add(paragraph);
this.radRichTextBox.Document.Sections.Add(section);

I hope this helps. Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Buttons
Asked by
Valentin
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or