WPF RadRichTextDocument and InlineUiElement size

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

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
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(new Span("Test"));

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

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.

Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question