New to Telerik UI for WPF? Start a free 30-day trial
Adjusting InlineUIContainer Vertical Position in RadRichTextBox
Updated on Mar 31, 2026
Environment
| Product | RichTextBox for UI for WPF |
| Version | Current |
Description
How to adjust the BaselineOffset of an InlineUIContainer in RadRichTextBox for WPF, in order to vertically offset the UI element from its original position.
Solution
The baseline offset is originally determined by the Height setting of the InlineUIContainer. This basically determines the top position of the element, relative to the bottom of the sibling document element (for example, a text span).
To manually control the baseline offset, create a custom CustomUIElementLayoutBox and override its BaselineOffset property.
C#
public class CustomUIElementLayoutBox : UIElementLayoutBox
{
private float? customBaselineOffset = null;
public CustomUIElementLayoutBox(DocumentElement parentElement, DocumentStructureCollection collection)
: base(parentElement, collection)
{
}
public float? CustomBaselineOffset { get => customBaselineOffset; set => customBaselineOffset = value; }
public override float BaselineOffset
{
get => CustomBaselineOffset.HasValue ? CustomBaselineOffset.Value : (float)this.AssociatedUIElementInline.Height;
}
}
To use the custom layout box, create a custom InlineUIContainer and override its CreateLayoutBox method.
C#
public class CustomInlineUIContainer : InlineUIContainer
{
public override LayoutBox CreateLayoutBox(DocumentStructureCollection documentCollection)
{
return new CustomUIElementLayoutBox(this, documentCollection);
}
protected override DocumentElement CreateNewElementInstance()
{
return new CustomInlineUIContainer();
}
protected override void CopyPropertiesFromOverride(DocumentElement fromElement)
{
base.CopyPropertiesFromOverride(fromElement);
if (fromElement.FirstLayoutBox is CustomUIElementLayoutBox fromBox && this.FirstLayoutBox is CustomUIElementLayoutBox toBox)
{
toBox.CustomBaselineOffset = fromBox.CustomBaselineOffset;
}
}
}
Then, use the custom baseline offset property to adjust the vertical position.
C#
var container = new CustomInlineUIContainer();
var layoutBox = (CustomUIElementLayoutBox)container.FirstLayoutBox;
var offset = 10;
layoutBox.CustomBaselineOffset = (float)(textBox.DesiredSize.Height - offset);
// other settings here
this.richTextBox.InsertInline(container);