WPF How to align text in InlineUIContainer content with external text in RichTextBox

Task: Make InlineUIContainer text content inline with external text

The standard behavior of InlineUIContainer content is when the bottom edge is embedded in the outer text.

You can move the contents of an InlineUIContainer using a RenderTransform, but a Y value must be selected for each type and font size - this is not an ideal way.

<RichTextBox>
    <FlowDocument>
        <Paragraph>
            LLL
            <InlineUIContainer>
                <Border Background="LightGoldenrodYellow">
                    <TextBlock Text="LLL"/>
                </Border>
            </InlineUIContainer>
            LLL
        </Paragraph>

        <Paragraph>
            LLL
            <InlineUIContainer>
                <Border Background="LightGoldenrodYellow">

                    <Border.RenderTransform>
                        <TranslateTransform Y="5" />
                    </Border.RenderTransform>

                    <TextBlock Text="LLL"/>

                </Border>    
            </InlineUIContainer>
            LLL
        </Paragraph>
    </FlowDocument>
</RichTextBox>

Example

How to align text in InlineUIContainer content with external text in RichTextBox regardless of font type and size?

+3
source share
1 answer

Have you tried playing with InlineUIContainer.BaselineAlignment

examples of use are given here

+7

All Articles